use vars qw($VERSION);
BEGIN {
- $VERSION = '2.01';
+ $VERSION = '2.06';
Time::HiRes->import('time') if eval {require Time::HiRes};
+ eval {require Scalar::Util};
}
sub croak {
my ($code, $found) = @{ $self->find_hook($hook, $step) };
if (! $code) {
croak "Could not find a method named ${step}_${hook} or ${hook}";
+ } elsif (! UNIVERSAL::isa($code, 'CODE')) {
+ croak "Value for $hook ($found) is not a code ref ($code)";
}
### record history
sub print_out {
my ($self, $step, $out) = @_;
- $self->cgix->print_content_type();
+ $self->cgix->print_content_type;
print $out;
}
sub swap_template {
my ($self, $step, $file, $swap) = @_;
- require CGI::Ex::Template;
my $args = $self->run_hook('template_args', $step);
+ my $copy = $self;
+ eval {require Scalar::Util; Scalar::Util::weaken($copy)};
+ $args->{'INCLUDE_PATH'} ||= sub { $copy->base_dir_abs || die "Could not find base_dir_abs while looking for template INCLUDE_PATH on step \"$step\"" };
+
+ require CGI::Ex::Template;
my $t = CGI::Ex::Template->new($args);
my $out = '';
return $out;
}
-sub template_args {
- my $self = shift;
- my $step = shift;
- return {
- INCLUDE_PATH => sub { $self->base_dir_abs || die "Could not find base_dir_abs while looking for template INCLUDE_PATH on step \"$step\"" },
- };
-}
+sub template_args { {} }
sub fill_template {
my ($self, $step, $outref, $fill) = @_;
if (ref($file) && ! UNIVERSAL::isa($file, 'SCALAR')) {
$hash = $file;
- ### read the file - if it fails - errors should be in the webserver error logs
+ ### read the file - if it is not found, errors will be in the webserver logs (all else dies)
} elsif ($file) {
- $hash = eval { $self->vob->get_validation($file) } || {};
+ $hash = $self->vob->get_validation($file) || {};
} else {
$hash = {};
return $self->{'hash_base'} ||= do {
### create a weak copy of self to use in closures
- my $copy;
- if (eval {require Scalar::Util} && defined &Scalar::Util::weaken) {
- $copy = $self;
- Scalar::Util::weaken($copy);
- } else {
- $copy = bless {%$self}, ref($self); # hackish way to avoid circular refs on older perls (pre 5.8)
- }
-
+ my $copy = $self;
+ eval {require Scalar::Util; Scalar::Util::weaken($copy)};
my $hash = {
script_name => $ENV{'SCRIPT_NAME'} || $0,
path_info => $ENV{'PATH_INFO'} || '',