Method-Autoload-0.02/0000755000076500007650000000000011325766112013767 5ustar mdavismdavisMethod-Autoload-0.02/README0000644000076500007650000000063711262031665014653 0ustar mdavismdavispod2text Method::Autoload.pm > README If this is still here it means the programmer was too lazy to create the readme file. You can create it now by using the command shown above from this directory. At the very least you should be able to use this set of instructions to install the module... perl Makefile.PL make make test make install If you are on a windows box you should use 'nmake' rather than 'make'. Method-Autoload-0.02/Changes0000644000076500007650000000024411325765240015263 0ustar mdavismdavisRevision history for Perl module Method::Autoload 0.02 2010-01-21 - Documention update to hide test package from CPAN index. 0.01 2009-10-04 -original version Method-Autoload-0.02/Todo0000644000076500007650000000007411262031665014616 0ustar mdavismdavisTODO list for Perl module Method::Autoload - Nothing yet Method-Autoload-0.02/MANIFEST0000644000076500007650000000051111325766112015115 0ustar mdavismdavisMANIFEST README LICENSE Todo Changes Makefile.PL lib/Method/Autoload.pm t/001_load.t t/002_packages.t t/003_DESTROY.t t/004_AUTOLOAD.t t/005_AUTOLOAD.t t/006_autoloaded.t scripts/Method-Autoload-example.pl scripts/lib/My/Fuz.pm scripts/lib/My/Baz.pm META.yml Module meta-data (added by MakeMaker) Method-Autoload-0.02/LICENSE0000644000076500007650000000276111262031665015000 0ustar mdavismdavisThe BSD License Copyright (c) 2009, Michael R. Davis All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the STOP, LLC nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Method-Autoload-0.02/t/0000755000076500007650000000000011325766112014232 5ustar mdavismdavisMethod-Autoload-0.02/t/003_DESTROY.t0000644000076500007650000000045711262234527016140 0ustar mdavismdavis# -*- perl -*- # t/001_load.t - check module loading and create testing directory use Test::More tests => 4; BEGIN { use_ok( 'Method::Autoload' ); } my $object = Method::Autoload->new (); isa_ok ($object, 'Method::Autoload'); is($object->DESTROY, "0E0", 'DESTORY'); ok($object->DESTROY, 'DESTORY'); Method-Autoload-0.02/t/006_autoloaded.t0000644000076500007650000000134111262236734017126 0ustar mdavismdavis# -*- perl -*- # t/001_load.t - check module loading and create testing directory use Test::More tests => 8; BEGIN { use_ok( 'Method::Autoload' ); } my $object; $object=Method::Autoload->new(packages=>[qw{My::Foo My::Bar}]); isa_ok ($object, 'Method::Autoload'); is($object->foo, "My::Foo::foo", 'AUTOLOAD from inline package'); is($object->bar, "My::Bar::bar", 'AUTOLOAD from inline package'); my $hash=$object->autoloaded; isa_ok($hash, "HASH"); isa_ok(scalar($object->autoloaded), "HASH"); is($object->autoloaded->{"foo"}, "My::Foo", 'autoloaded'); is($object->autoloaded->{"bar"}, "My::Bar", 'autoloaded'); package My::Foo; sub foo {"My::Foo::foo"}; 1; package My::Bar; sub foo {"My::Bar::foo"}; sub bar {"My::Bar::bar"}; 1; Method-Autoload-0.02/t/001_load.t0000644000076500007650000000034611262233254015715 0ustar mdavismdavis# -*- perl -*- # t/001_load.t - check module loading and create testing directory use Test::More tests => 2; BEGIN { use_ok( 'Method::Autoload' ); } my $object = Method::Autoload->new (); isa_ok ($object, 'Method::Autoload'); Method-Autoload-0.02/t/004_AUTOLOAD.t0000644000076500007650000000101011262236306016177 0ustar mdavismdavis# -*- perl -*- # t/001_load.t - check module loading and create testing directory use Test::More tests => 4; BEGIN { use_ok( 'Method::Autoload' ); } my $object; $object=Method::Autoload->new(packages=>[qw{My::Foo My::Bar}]); isa_ok ($object, 'Method::Autoload'); is($object->foo, "My::Foo::foo", 'AUTOLOAD from inline package'); is($object->bar, "My::Bar::bar", 'AUTOLOAD from inline package'); package My::Foo; sub foo {"My::Foo::foo"}; 1; package My::Bar; sub foo {"My::Bar::foo"}; sub bar {"My::Bar::bar"}; 1; Method-Autoload-0.02/t/005_AUTOLOAD.t0000644000076500007650000000101011262236275016205 0ustar mdavismdavis# -*- perl -*- # t/001_load.t - check module loading and create testing directory use Test::More tests => 4; BEGIN { use_ok( 'Method::Autoload' ); } my $object; $object=Method::Autoload->new(packages=>[qw{My::Bar My::Foo}]); isa_ok ($object, 'Method::Autoload'); is($object->foo, "My::Bar::foo", 'AUTOLOAD from inline package'); is($object->bar, "My::Bar::bar", 'AUTOLOAD from inline package'); package My::Foo; sub foo {"My::Foo::foo"}; 1; package My::Bar; sub foo {"My::Bar::foo"}; sub bar {"My::Bar::bar"}; 1; Method-Autoload-0.02/t/002_packages.t0000644000076500007650000000206711262234143016555 0ustar mdavismdavis# -*- perl -*- # t/001_load.t - check module loading and create testing directory use Test::More tests => 17; BEGIN { use_ok( 'Method::Autoload' ); } my $object=Method::Autoload->new(packages=>[qw{One Two}]); isa_ok ($object, 'Method::Autoload'); isa_ok (scalar($object->packages), 'ARRAY'); is(scalar(@{$object->packages}), 2, 'packages 1'); is($object->packages->[0], "One", 'packages 2'); is($object->packages->[1], "Two", 'packages 3'); $object->pushPackages("Three", "Four"); is(scalar(@{$object->packages}), 4, 'packages 4'); is($object->packages->[0], "One", 'packages 5'); is($object->packages->[1], "Two", 'packages 6'); is($object->packages->[2], "Three", 'packages 7'); is($object->packages->[3], "Four", 'packages 8'); $object->unshiftPackages("Zero"); is(scalar(@{$object->packages}), 5, 'packages 9'); is($object->packages->[0], "Zero", 'packages 10'); is($object->packages->[1], "One", 'packages 11'); is($object->packages->[2], "Two", 'packages 12'); is($object->packages->[3], "Three", 'packages 13'); is($object->packages->[4], "Four", 'packages 14'); Method-Autoload-0.02/Makefile.PL0000644000076500007650000000076611325764672015763 0ustar mdavismdavisuse ExtUtils::MakeMaker; WriteMakefile( NAME => 'Method::Autoload', VERSION_FROM => 'lib/Method/Autoload.pm', AUTHOR => 'Michael R. Davis (domain=>michaelrdavis,tld=>com,account=>perl)', ABSTRACT_FROM=> 'lib/Method/Autoload.pm', PREREQ_PM => { 'Test::Simple' => 0.44, 'UNIVERSAL::require' => 0, 'warnings' => 0, 'strict' => 0, }, ); Method-Autoload-0.02/META.yml0000664000076500007650000000072111325766112015242 0ustar mdavismdavis# http://module-build.sourceforge.net/META-spec.html #XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX# name: Method-Autoload version: 0.02 version_from: lib/Method/Autoload.pm installdirs: site requires: strict: 0 Test::Simple: 0.44 UNIVERSAL::require: 0 warnings: 0 distribution_type: module generated_by: ExtUtils::MakeMaker version 6.30 Method-Autoload-0.02/lib/0000755000076500007650000000000011325766112014535 5ustar mdavismdavisMethod-Autoload-0.02/lib/Method/0000755000076500007650000000000011325766112015755 5ustar mdavismdavisMethod-Autoload-0.02/lib/Method/Autoload.pm0000644000076500007650000001155511325765104020072 0ustar mdavismdavispackage Method::Autoload; use strict; use warnings; use UNIVERSAL::require; our $VERSION='0.02'; our $AUTOLOAD; =head1 NAME Method::Autoload - Autoloads methods from a list of packages into the current package =head1 SYNOPSIS package MyPackage; use base qw{Method::Autoload} =head1 DESCRIPTION The Method::Autoload base class package is used to autoload methods from a list of packages where you may not know what methods are available until run time. A good use of this package is programming support for user contributed packages or user contributed plugins. =head1 USAGE use MyPackage; my $object=MyPackage->new(%hash); #provides new and initialize methods $object->pushPackages("My::Bar"); #appends to "packages" array $object->unshiftPackages("My::Foo"); #prepends to "packages" array use MyPackage; my $object=MyPackage->new(packages=>["My::Foo", "My::Bar"]); $object->foo; #from My::Foo $object->bar; #from My::Bar =head1 CONSTRUCTOR =head2 new my $object=MyPackage->new(%hash); my $object=MyPackage->new(package=>["My::Package1", "My::Package2"]); =cut sub new { my $this=shift; my $class=ref($this) || $this; my $self={}; bless $self, $class; $self->initialize(@_); return $self; } =head2 initialize =cut sub initialize { my $self=shift; %$self=@_; } =head1 METHODS PUBLIC =head2 packages Returns the current list of packages in the "packages" array. my @package=$object->packages; #() my $package=$object->packages; #[] =cut sub packages { my $self=shift; $self->{"packages"}=[] unless ref($self->{"packages"}) eq "ARRAY"; return wantarray ? @{$self->{"packages"}} : $self->{"packages"}; } =head2 pushPackages Pushes packages on to the "packages" array. $object->pushPackages("My::Bar"); $object->pushPackages(@packages); =cut sub pushPackages { my $self=shift; push @{$self->packages}, @_ if @_; return $self->packages; } =head2 unshiftPackages Unshifts packages on to the "packages" array. Use this if you want to override a "default" package. Please use with care. $object->unshiftPackages("My::Foo"); $object->unshiftPackages(@packages); =cut sub unshiftPackages { my $self=shift; unshift @{$self->packages}, @_ if @_; return $self->packages; } =head2 autoloaded Returns a hash of autoloaded methods and the classes that they came from. my %hash=$object->autoloaded; #() my $hash=$object->autoloaded; #{} =cut sub autoloaded { my $self=shift; $self->{"autoloaded"}={} unless ref($self->{"autoloaded"}) eq "HASH"; return wantarray ? @{$self->{"autoloaded"}} : $self->{"autoloaded"}; } =head1 METHODS PRIVATE =head2 DESTROY ("Global" method) We define DESTROY in this package so that it does not call AUTOLOAD but you may overload this method in your package, if you need it. =cut sub DESTROY {return "0E0"}; =head2 AUTOLOAD ("Global" method) AUTOLOAD is a "global" method. Please review the limitations on inheriting this method. =cut sub AUTOLOAD { my $self=shift; my $method=$AUTOLOAD; $method=~s/.*://; #warn sprintf("Autoloading Method: %s\n", $method); foreach my $class ($self->packages) { if ($class->can($method)) { #warn(sprintf(qq{Package "%s" is loaded and method "%s" is supported\n}, $class, $method)); $self->autoload($class, $method); last; #for performance and in case another package defines method. } else { #warn sprintf("Loading Package: %s\n", $class); $class->use; if ($@) { #warn(sprintf(qq{Warning: Failed to use package "%s". Is it installed?\n}, $class)); } else { if ($class->can($method)) { $self->autoload($class, $method); last; #for performance and in case another package defines method. } } } } die(sprintf(qq{Error: Could not autoload method "%s" from packages %s.\n}, $method, join(", ", map {qq{"$_"}} $self->packages))) unless $self->can($method); return $self->$method(@_); } =head2 autoload my $subref=$object->autoload($class, $method); =cut sub autoload { my $syntax=q{Error: autoload syntax $obj->autoload($class, $method)}; my $self=shift or die($syntax); my $class=shift or die($syntax); my $method=shift or die($syntax); my $sub=join("::", $class, $method); #warn sprintf(qq{Importing method "%s" from class "%s"\n}, $method, $class); $self->autoloaded->{$method}=$class; no strict qw{refs}; return *$method=\&{$sub}; } =head1 BUGS DavisNetworks.com provides support services for all Perl applications including this package. =head1 SUPPORT =head1 AUTHOR Michael R. Davis CPAN ID: MRDVT STOP, LLC domain=>michaelrdavis,tld=>com,account=>perl http://www.stopllc.com/ =head1 COPYRIGHT This program is free software licensed under the... The BSD License The full text of the license can be found in the LICENSE file included with this module. =head1 SEE ALSO L AUTOMETHOD method, =cut 1; Method-Autoload-0.02/scripts/0000755000076500007650000000000011325766112015456 5ustar mdavismdavisMethod-Autoload-0.02/scripts/Method-Autoload-example.pl0000644000076500007650000000204111262250067022424 0ustar mdavismdavis#!/usr/bin/perl use strict; use warnings; use lib qw{./lib}; use My::Fuz; =head1 NAME Method-Autoload-example.pl - Method::Autoload Example =cut my $obj=MyPackage->new(packages=>[qw{My::Foo My::Bar My::Baz My::Fuz My::Zuz}]); printf "Search Packages: %s\n", join(",", $obj->packages); printf "foo: %s\n", $obj->foo; #in line package with duplicate method printf "bar: %s\n", $obj->bar; #in line package printf "baz: %s\n", $obj->baz; #lib loaded from file printf "fuz: %s\n", $obj->fuz; #lib loaded used by script printf "foo: %s\n", $obj->foo; #autoloaded printf "bar: %s\n", $obj->bar; #autoloaded printf "baz: %s\n", $obj->baz; #autoloaded printf "fuz: %s\n", $obj->fuz; #autoloaded print map {sprintf("Autoloaded: %s => %s\n", $_, $obj->autoloaded->{$_})} sort keys %{$obj->autoloaded}; package MyPackage; use strict; use warnings; use base qw{Method::Autoload}; 1; package My::Foo; use strict; use warnings; sub foo {"My::Foo::foo"}; 1; package My::Bar; use strict; use warnings; sub foo {"My::Bar::foo"}; sub bar {"My::Bar::bar"}; 1; Method-Autoload-0.02/scripts/lib/0000755000076500007650000000000011325766112016224 5ustar mdavismdavisMethod-Autoload-0.02/scripts/lib/My/0000755000076500007650000000000011325766112016611 5ustar mdavismdavisMethod-Autoload-0.02/scripts/lib/My/Fuz.pm0000644000076500007650000000014011325764270017711 0ustar mdavismdavispackage #hide from CPAN My::Fuz; use strict; use warnings; sub fuz {"My::Fuz::fuz"}; 1; Method-Autoload-0.02/scripts/lib/My/Baz.pm0000644000076500007650000000022411325764315017664 0ustar mdavismdavispackage #hide from CPAN My::Baz; use strict; use warnings; sub foo {"My::Baz::foo"}; sub bar {"My::Baz::bar"}; sub baz {"My::Baz::baz"}; 1;