Pickles
view release on metacpan or search on metacpan
lib/Pickles/Config.pm view on Meta::CPAN
# In 5.8.8 at least, putting $self in an evaled code produces
# extra warnings (and possibly break the behavior of __path_to)
# so we create a private closure, and plant the closure into
# the generated packes
$self->{__FILES} = [];
my $path_to = sub { $self->path_to(@_) };
my $load_file = sub {
my $file = $path_to->( @_ );
delete $INC{$file};
my $subconf = require $file;
# death context should be at the calling config file level
Carp::croak("Could not parse $file: $@") if $@;
Carp::croak("Could not do $file: $!") if ! defined $subconf;
Carp::croak("Could not run $file") if ! $subconf;
push @{$self->{__FILES}}, $file;
return $subconf;
};
for my $file( @{$files} ) {
lib/Pickles/Config.pm view on Meta::CPAN
{ # XXX This is where we plant that closure
no strict 'refs';
no warnings 'redefine';
*{"$fqname\::__path_to"} = $path_to;
*{"$fqname\::load_file"} = $load_file;
}
my $config_pkg = sprintf <<'SANDBOX', $fqname;
package %s;
{
my $conf = require $file or die $!;
$conf;
}
SANDBOX
delete $INC{$file};
my $conf = eval $config_pkg || +{};
if ($@) {
warn "Error while trying to read config file $file: $@";
}
%config = (
%config,
lib/Pickles/Container.pm view on Meta::CPAN
no warnings 'redefine';
local *register = sub($$;$) {
$o->( $self, @_ );
};
local *load_file = sub(@) {
my $c = $self->get('config');
# XXX what if there's no config?
my $file = $c->path_to(@_);
delete $INC{$file};
my $rv = require $file;
Carp::croak("Failed to parse file $file: $@") if $@;
Carp::croak("Failed to run file (did you return a true value?)") unless $rv;
return $rv;
};
my $result = do $file;
die "Failed to parse file $file: $@" if $@;
die "Failed to run file (did you return a true value?)" unless $result;
$self;
}
lib/Pickles/Dispatcher.pm view on Meta::CPAN
if (! File::Spec->file_name_is_absolute( $file ) ) {
$file = Cwd::abs_path( $file );
}
my $fqname = sprintf '%s::%s', $class, $pkg;
my $router_pkg = sprintf <<'SANDBOX', $fqname;
package %s;
use Router::Simple::Declare;
{
delete $INC{$file};
my $conf = require $file or die $!;
$conf;
}
SANDBOX
my $router = eval $router_pkg;
if (! eval { $router->isa( 'Router::Simple' ) } || $@ ) {
Carp::croak("file $args{file} returned something other than Router::Simple");
}
bless { router => $router }, $class;
}
( run in 0.525 second using v1.01-cache-2.11-cpan-0d8aa00de5b )