Data::Phrasebook::Loader - Plugin Loader module


Data-Phrasebook documentation Contained in the Data-Phrasebook distribution.

Index


Code Index:

NAME

Top

Data::Phrasebook::Loader - Plugin Loader module

SYNOPSIS

Top

  my $loader = Data::Phrasebook::Loader->new( class => 'Text' );

DESCRIPTION

Top

Data::Phrasebook::Loader acts as an autoloader for phrasebook plugins.

CONSTRUCTOR

Top

new

new takes one optional named argument: the class. It returns a new instance to the class. Any further arguments to new are given to the new method of the appropriate class.

If no class is specified the default class of 'Text' is used.

  my $loader = Data::Phrasebook::Loader->new();

  OR

  my $loader = Data::Phrasebook::Loader->new( class => 'Text' );

SEE ALSO

Top

Data::Phrasebook.

Known implementations

Data::Phrasebook::Loader::Text, Data::Phrasebook::Loader::YAML, Data::Phrasebook::Loader::Ini, Data::Phrasebook::Loader::XML, Data::Phrasebook::Loader::DBI.

SUPPORT

Top

Please see the README file.

AUTHOR

Top

  Original author: Iain Campbell Truskett (16.07.1979 - 29.12.2003)
  Maintainer: Barbie <barbie@cpan.org> since January 2004.
  for Miss Barbell Productions <http://www.missbarbell.co.uk>.

COPYRIGHT AND LICENSE

Top


Data-Phrasebook documentation Contained in the Data-Phrasebook distribution.
package Data::Phrasebook::Loader;
use strict;
use warnings FATAL => 'all';
use base qw( Data::Phrasebook::Debug );
use Carp qw( croak );

use Module::Pluggable   search_path => ['Data::Phrasebook::Loader'];

use vars qw($VERSION);
$VERSION = '0.31';

my $DEFAULT_CLASS = 'Text';

sub new
{
    my $self  = shift;
    my %args  = @_;
    my $class = delete $args{class} || 'Text';

    if($self->debug) {
		$self->store(3,"$self->new IN");
		$self->store(4,"$self->new class=[$class]");
	}

    # in the event we have been subclassed
    $self->search_path( add => "$self" );

    my $plugin;
    my @plugins = $self->plugins();
    for(@plugins) {
        $plugin = $_    if($_ =~ /\b$class$/);
    }

    croak("no loader available of that name\n") unless($plugin);
    eval "CORE::require $plugin";
    croak "Couldn't require $plugin : $@" if $@;

    $self->store(4,"$self->new plugin=[$plugin]")	if($self->debug);
    return $plugin->new( %args );
}

1;

__END__