Module-Pluggable-Fast-0.19/000755 000765 000765 00000000000 11315205417 015107 5ustar00marcus000000 000000 Module-Pluggable-Fast-0.19/Changes000644 000765 000765 00000001505 11315205343 016401 0ustar00marcus000000 000000 Revision history for Perl extension Module::Pluggable::Fast
0.19 Fri Dec 25 00:00:00 2009
- Add untaint patch from GEOFFR
0.18 Fri Dec 16 00:00:00 2005
- Fixed tests
0.17 Thu Dec 15 00:00:00 2005
- Added tests from Module::Pluggable
- Updated regex
- Fixed to properly die on error messages from components.
(Andy Grundman)
0.16 Fri Jun 03 02:47:00 2005
- added callback option
0.15 Wen Apr 27 00:00:00 2005
- added require option
0.14 Sat Apr 23 16:42:00 2005
- die on syntax errors
0.13 Mon Mar 7 20:00:00 2005
- fixed prereqs (Juergen Peters)
0.12 Tue Jan 25 20:00:00 2005
- fixed dependencies (Marcus Ramberg)
0.11 Mon Dec 20 20:00:00 2004
- faster instantiation
0.10 Sun Dec 19 18:00:00 2004
- original version.
Module-Pluggable-Fast-0.19/Fast.pm000644 000765 000765 00000010124 11315205206 016334 0ustar00marcus000000 000000 package Module::Pluggable::Fast;
use strict;
use vars '$VERSION';
use UNIVERSAL::require;
use Carp qw/croak carp/;
use File::Find ();
use File::Basename;
use File::Spec::Functions qw/splitdir catdir abs2rel/;
$VERSION = '0.19';
=head1 NAME
Module::Pluggable::Fast - Fast plugins with instantiation
=head1 SYNOPSIS
package MyClass;
use Module::Pluggable::Fast
name => 'components',
search => [ qw/MyClass::Model MyClass::View MyClass::Controller/ ];
package MyOtherClass;
use MyClass;
my @components = MyClass->components;
=head1 DESCRIPTION
Similar to C but instantiates plugins as soon as they're
found, useful for code generators like C.
=head2 OPTIONS
=head3 name
Name for the exported method.
Defaults to plugins.
=head3 require
If true, only require plugins.
=head3 callback
Codref to be called instead of the default instantiate callback.
=head3 search
Arrayref containing a list of namespaces to search for plugins.
Defaults to the ::Plugin:: namespace of the calling class.
=cut
sub import {
my ( $class, %args ) = @_;
my $caller = caller;
no strict 'refs';
*{ "$caller\::" . ( $args{name} || 'plugins' ) } = sub {
my $self = shift;
$args{search} ||= ["$caller\::Plugin"];
$args{require} ||= 0;
$args{callback} ||= sub {
my $plugin = shift;
my $obj = $plugin;
eval { $obj = $plugin->new(@_) };
carp qq/Couldn't instantiate "$plugin", "$@"/ if $@;
return $obj;
};
my %plugins;
foreach my $dir ( exists $INC{'blib.pm'} ? grep { /blib/ } @INC : @INC )
{
foreach my $searchpath ( @{ $args{search} } ) {
my $sp = catdir( $dir, ( split /::/, $searchpath ) );
next unless ( -e $sp && -d $sp );
foreach my $file ( _find_packages($sp) ) {
my ( $name, $directory ) = fileparse $file, qr/\.pm/;
$directory = abs2rel $directory, $sp;
my $plugin = join '::', splitdir catdir $searchpath,
$directory, $name;
$plugin->require;
my $error = $UNIVERSAL::require::ERROR;
die qq/Couldn't load "$plugin", "$error"/ if $error;
unless ( $plugins{$plugin} ) {
$plugins{$plugin} =
$args{require}
? $plugin
: $args{callback}->( $plugin, @_ );
}
for my $class ( _list_packages($plugin) ) {
next if $plugins{$class};
$plugins{$class} =
$args{require}
? $class
: $args{callback}->( $class, @_ );
}
}
}
}
return values %plugins;
};
}
sub _find_packages {
my $search = shift;
my @files = ();
my $wanted = sub {
my $path = $File::Find::name;
return unless $path =~ /\w+\.pm$/;
return unless $path =~ /\A(.+)\z/;
$path = $1; # untaint
# don't include symbolig links pointing into nowhere
# (e.g. emacs lock-files)
return if -l $path && !-e $path;
$path =~ s#^\\./##;
push @files, $path;
};
File::Find::find( { no_chdir => 1, wanted => $wanted }, $search );
return @files;
}
sub _list_packages {
my $class = shift;
$class .= '::' unless $class =~ m!::$!;
no strict 'refs';
my @classes;
for my $subclass ( grep !/^main::$/, grep /::$/, keys %$class ) {
$subclass =~ s!::$!!;
next if $subclass =~ /^::/;
push @classes, "$class$subclass";
push @classes, _list_packages("$class$subclass");
}
return @classes;
}
=head1 AUTHOR
Sebastian Riedel, C
=head1 COPYRIGHT
This program is free software, you can redistribute it and/or modify it under
the same terms as Perl itself.
=head1 SEE ALSO
L
=cut
1;
Module-Pluggable-Fast-0.19/Makefile.PL000644 000765 000765 00000000301 11315205206 017047 0ustar00marcus000000 000000 use ExtUtils::MakeMaker;
WriteMakefile(
'NAME' => 'Module::Pluggable::Fast',
'VERSION_FROM' => 'Fast.pm',
'PREREQ_PM' => { UNIVERSAL::require => 0, File::Find => 0 }
);
Module-Pluggable-Fast-0.19/MANIFEST000644 000765 000765 00000000454 11315205206 016237 0ustar00marcus000000 000000 Changes
Fast.pm
Makefile.PL
MANIFEST This list of files
META.yml
README
t/01use.t
t/02pod.t
t/03podcoverage.t
t/09require.t
t/10innerpack_noinner.t
t/lib/InnerTest/Plugin/Foo.pm
t/lib/MyTest/Extend/Plugin/Bar.pm
t/lib/MyTest/Plugin/Bar.pm
t/lib/MyTest/Plugin/Foo.pm
t/lib/MyTest/Plugin/Quux/Foo.pm
Module-Pluggable-Fast-0.19/META.yml000664 000765 000765 00000001021 11315205417 016354 0ustar00marcus000000 000000 --- #YAML:1.0
name: Module-Pluggable-Fast
version: 0.19
abstract: ~
author: []
license: unknown
distribution_type: module
configure_requires:
ExtUtils::MakeMaker: 0
build_requires:
ExtUtils::MakeMaker: 0
requires:
File::Find: 0
UNIVERSAL::require: 0
no_index:
directory:
- t
- inc
generated_by: ExtUtils::MakeMaker version 6.54
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: 1.4
Module-Pluggable-Fast-0.19/README000644 000765 000765 00000001637 11315205206 015772 0ustar00marcus000000 000000 NAME
Module::Pluggable::Fast - Fast plugins with instantiation
SYNOPSIS
package MyClass;
use Module::Pluggable::Fast
name => 'components',
search => [ qw/MyClass::Model MyClass::View MyClass::Controller/ ];
package MyOtherClass;
use MyClass;
my @components = MyClass->components;
DESCRIPTION
Similar to "Module::Pluggable" but instantiates plugins as soon as
they're found, useful for code generators like "Class::DBI::Loader".
OPTIONS
name
Name for the exported method. Defaults to plugins.
search
Arrayref containing a list of namespaces to search for plugins. Defaults
to the ::Plugin:: namespace of the calling class.
AUTHOR
Sebastian Riedel, "sri@cpan.org"
COPYRIGHT
This program is free software, you can redistribute it and/or modify it
under the same terms as Perl itself.
SEE ALSO
Module::Pluggable
Module-Pluggable-Fast-0.19/t/000755 000765 000765 00000000000 11315205417 015352 5ustar00marcus000000 000000 Module-Pluggable-Fast-0.19/t/01use.t000644 000765 000765 00000000130 11315205205 016461 0ustar00marcus000000 000000 #!perl -wT
use strict;
use Test::More tests => 1;
use_ok('Module::Pluggable::Fast');
Module-Pluggable-Fast-0.19/t/02pod.t000644 000765 000765 00000000276 11315205205 016463 0ustar00marcus000000 000000 use Test::More;
eval "use Test::Pod 1.14";
plan skip_all => 'Test::Pod 1.14 required' if $@;
plan skip_all => 'set TEST_POD to enable this test' unless $ENV{TEST_POD};
all_pod_files_ok();
Module-Pluggable-Fast-0.19/t/03podcoverage.t000644 000765 000765 00000000325 11315205205 020173 0ustar00marcus000000 000000 use Test::More;
eval "use Test::Pod::Coverage 1.04";
plan skip_all => 'Test::Pod::Coverage 1.04 required' if $@;
plan skip_all => 'set TEST_POD to enable this test' unless $ENV{TEST_POD};
all_pod_coverage_ok();
Module-Pluggable-Fast-0.19/t/09require.t000644 000765 000765 00000000561 11315205206 017362 0ustar00marcus000000 000000 #!perl-wT
use strict;
use lib 't/lib';
use Test::More tests => 2;
my $t = MyTest->new();
ok($t->plugins());
ok(keys %{MyTest::Plugin::Foo::});
package MyTest;
use File::Spec::Functions qw(catdir);
use strict;
use Module::Pluggable::Fast (require => 1);
use base qw(Module::Pluggable::Fast);
sub new {
my $class = shift;
return bless {}, $class;
}
1;
Module-Pluggable-Fast-0.19/t/10innerpack_noinner.t000644 000765 000765 00000000775 11315205205 021406 0ustar00marcus000000 000000 #!perl-wT
use strict;
use lib 't/lib';
use Test::More tests => 3;
my $t = InnerTest->new();
my %plugins = map { $_ => 1 } $t->plugins;
ok(keys %plugins, "Got some plugins");
ok($plugins{'InnerTest::Plugin::Foo'}, "Got Foo");
ok(!$plugins{'InnerTest::Plugin::Bar'}, "Didn't get Bar - the inner package");
package InnerTest;
use strict;
use Module::Pluggable::Fast require => 1, inner => 0;
use base qw(Module::Pluggable::Fast);
sub new {
my $class = shift;
return bless {}, $class;
}
1;
Module-Pluggable-Fast-0.19/t/lib/000755 000765 000765 00000000000 11315205417 016120 5ustar00marcus000000 000000 Module-Pluggable-Fast-0.19/t/lib/InnerTest/000755 000765 000765 00000000000 11315205417 020033 5ustar00marcus000000 000000 Module-Pluggable-Fast-0.19/t/lib/MyTest/000755 000765 000765 00000000000 11315205417 017345 5ustar00marcus000000 000000 Module-Pluggable-Fast-0.19/t/lib/MyTest/Extend/000755 000765 000765 00000000000 11315205417 020574 5ustar00marcus000000 000000 Module-Pluggable-Fast-0.19/t/lib/MyTest/Plugin/000755 000765 000765 00000000000 11315205417 020603 5ustar00marcus000000 000000 Module-Pluggable-Fast-0.19/t/lib/MyTest/Plugin/Bar.pm000644 000765 000765 00000000062 11315205204 021635 0ustar00marcus000000 000000 package MyTest::Plugin::Bar;
use strict;
1;
Module-Pluggable-Fast-0.19/t/lib/MyTest/Plugin/Foo.pm000644 000765 000765 00000000062 11315205204 021654 0ustar00marcus000000 000000 package MyTest::Plugin::Foo;
use strict;
1;
Module-Pluggable-Fast-0.19/t/lib/MyTest/Plugin/Quux/000755 000765 000765 00000000000 11315205417 021545 5ustar00marcus000000 000000 Module-Pluggable-Fast-0.19/t/lib/MyTest/Plugin/Quux/Foo.pm000644 000765 000765 00000000070 11315205204 022615 0ustar00marcus000000 000000 package MyTest::Plugin::Quux::Foo;
use strict;
1;
Module-Pluggable-Fast-0.19/t/lib/MyTest/Extend/Plugin/000755 000765 000765 00000000000 11315205417 022032 5ustar00marcus000000 000000 Module-Pluggable-Fast-0.19/t/lib/MyTest/Extend/Plugin/Bar.pm000644 000765 000765 00000000256 11315205203 023070 0ustar00marcus000000 000000 package MyTest::Extend::Plugin::Bar;
use strict;
sub new {
my $class = shift;
my %self = @_;
return bless \%self, $class;
}
sub nork {
return $_[0]->{'nork'};
}
1;
Module-Pluggable-Fast-0.19/t/lib/InnerTest/Plugin/000755 000765 000765 00000000000 11315205417 021271 5ustar00marcus000000 000000 Module-Pluggable-Fast-0.19/t/lib/InnerTest/Plugin/Foo.pm000644 000765 000765 00000000135 11315205205 022344 0ustar00marcus000000 000000 package InnerTest::Plugin::Foo;
use strict;
package InnerTest::Plugin::Bar;
use strict;
1;