package Admin_server::Parser; use MooseX::FollowPBP; # Simon Cozens Perl Best Practices. use Moose; # Sugar!! use Module::Pluggable::Object; # To enable application plugins. use aliased 'Admin_server::Interface::ParserInterface'; #---------------------------------------------------------- # Define attributes. #---------------------------------------------------------- has 'plugins' => ( is => 'ro', lazy_build => 1, isa => 'HashRef' ); #---------------------------------------------------------- # Define methods. #---------------------------------------------------------- sub _build_plugins { #=== FUNCTION ==================================== # NAME: _build_plugins # PURPOSE: To build up the applications hash. # PARAMETERS: None. # RETURNS: Nothing. # DESCRIPTION: Populates the applications hash with the list of # available application parser plugins. # THROWS: no exceptions # COMMENTS: none #=============================================== my ($self) = @_; my $base = __PACKAGE__ . '::Plugin';# Location of parser plugins. my %parser_plugins; # Stores the instantiated plugins. # Scan plugins at $base. my $mpo = Module::Pluggable::Object->new( search_path => [$base] ); my @available_plugins = $mpo->plugins(); print 'Found plugins ...', "@available_plugins", "\n"; # Load the available plugins. foreach my $plugin (@available_plugins) { print "Loading plugin $plugin", "\n"; Class::MOP::load_class($plugin); print "finished loading $plugin" . "\n" if ( Class::MOP::is_class_loaded($plugin) ); # Ensure that each class confirms to the plugin API. confess("Plugin $plugin in ${base}" . ' namespace doesn\'t implement ParserInterface.' ) unless ( $plugin->does(ParserInterface) ); # Record and instantiate the valid plugin objects in a hash. ( my $plugin_name = $plugin ) =~ s/\Q${base}::\E//; $parser_plugins{$plugin_name} = $plugin->new(); } print STDOUT sort keys %parser_plugins, "\n"; return \%parser_plugins; } # ---------- end of subroutine _build_applications ----------