Anansi-Actor
view release on metacpan or search on metacpan
lib/Anansi/Actor.pm view on Meta::CPAN
)) {
Anansi::Actor->new(
PACKAGE => 'DBI',
);
print Data::Dumper::Dumper(DBI->available_drivers());
}
=head1 DESCRIPTION
This is a dynamic usage module definition that manages the loading of a required
namespace and blessing of an object of the namespace as required. Uses L<Fcntl>,
L<File::Find>, L<File::Spec::Functions> and L<FileHandle>.
=cut
our $VERSION = '0.15';
use base qw(Anansi::Singleton);
use Fcntl ':flock';
lib/Anansi/Actor.pm view on Meta::CPAN
Either an object or a string of this namespace.
=item parameters I<(Hash)>
Named parameters.
=over 4
=item BLESS I<(String, Optional)>
The name of the subroutine within the namespace that creates a blessed object of
the namespace. Defaults to I<"new">.
=item IMPORT I<(Array, Optional)>
An array of the names to import from the loading module.
=item PACKAGE I<(String, Required)>
The namespace of the module to load.
=item PARAMETERS I<(Array B<or> Hash, Optional)>
Either An array or a hash of the parameters to pass to the blessing subroutine.
=back
=back
Overrides I<(L<Anansi::Singleton::new|Anansi::Singleton/"new">)>. Instantiates
an object instance of a dynamically loaded module.
=cut
lib/Anansi/Actor.pm view on Meta::CPAN
return if(ref($parameters{PARAMETERS}) !~ /^ARRAY$/i);
}
if(defined($parameters{IMPORT})) {
return if(ref($parameters{IMPORT}) !~ /^ARRAY$/i);
foreach my $import (@{$parameters{IMPORT}}) {
return if(ref($import) !~ /^$/);
return if($import !~ /^[a-zA-Z_]+[a-zA-Z0-9_]*$/);
}
}
my $package = $parameters{PACKAGE};
my $bless = $parameters{BLESS};
my $self;
eval {
(my $file = $package) =~ s/::/\//g;
require $file.'.pm';
if(defined($parameters{IMPORT})) {
$package->import(@{$parameters{IMPORT}});
} else {
$package->import();
}
if(defined($parameters{PARAMETERS})) {
$self = $package->$bless(@{$parameters{PARAMETERS}});
} else {
$self = $package->$bless();
}
1;
} or do {
my $error = $@;
return ;
};
return $self;
}
( run in 1.594 second using v1.01-cache-2.11-cpan-b32c08c6d1a )