Skip to content
Snippets Groups Projects
Autoload.pm 4.86 KiB
package 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