# Copyright 2002-2007 Interchange Development Group and others
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.  See the LICENSE file for details.

UserTag include             Order        file locale
UserTag include             PosNumber    2
UserTag include             Version      1.8
UserTag include             Routine      <<EOR
sub {
	my ($file, $locale) = @_;
	$locale = 1 unless defined $locale;

	$::Instance->{include_depth} ||= 0;
	my $limit = $Vend::Cfg->{Limit}{include_depth} || 10;

	if($::Instance->{include_depth}++ >= $limit) {
		logOnce(
				'error',
				"Depth of include (%s) exceeds limit of %s for file %s.", 
				$::Instance->{include_depth},
				$limit,
				$file,
			);
		return;
	}

	my $out = Vend::Interpolate::interpolate_html(
					Vend::Util::readfile($file, undef, $locale)
				);
	$::Instance->{include_depth}--;
	return $out;
}
EOR
