DBD-Sys

 view release on metacpan or  search on metacpan

lib/DBD/Sys/PluginManager.pm  view on Meta::CPAN

package DBD::Sys::PluginManager;

use strict;
use warnings;

=head1 NAME

DBD::Sys::Plugin - embed own tables to DBD::Sys

=head1 SYNOPSIS

    my $dbh = DBI->connect( "DBI:Sys:", undef, undef, {
	sys_pluginmgr_class => "DBD::Sys::PluginManager", }
    ) or die $DBI:errstr;

=cut

use vars qw($VERSION);

require DBD::Sys::Plugin;
require DBD::Sys::CompositeTable;

use Scalar::Util qw(weaken);
use Carp qw(croak);
use Params::Util qw(_HASH _ARRAY);
use Clone qw(clone);

use Module::Pluggable
  require     => 1,
  search_path => ['DBD::Sys::Plugin'],
  inner       => 0,
  only        => qr/^DBD::Sys::Plugin::\p{Word}+$/;

$VERSION = "0.102";

=head1 DESCRIPTION

The plugin manager provides a basic management of plugins to extend
DBD::Sys with additional tables. All plugins are expected to be directly
under the C<DBD::Sys::Plugin> namespace:

    use Module::Pluggable
      require     => 1,
      search_path => ['DBD::Sys::Plugin'],
      inner       => 0,
      only        => qr/^DBD::Sys::Plugin::\p{Word}+$/;

=head1 METHODS

=head2 new

Instantiates a new plugin manager and loads all plugins and available
tables. During the loading of all that modules, some internal dictionaries
are created to find the implementor classes for tables and all valid
attributes to tweak the data of the tables.

=cut

sub new
{
    my $class    = $_[0];
    my %instance = ();
    my $self     = bless( \%instance, $class );
    my @tableAttrs;

    foreach my $plugin ( $self->plugins() )
    {
        croak "Invalid plugin: $plugin" unless ( $plugin->isa('DBD::Sys::Plugin') );
        my %pluginTables = $plugin->get_supported_tables();
        foreach my $pluginTable ( keys %pluginTables )
        {
            my $pte = lc $pluginTable;
            my @pluginClasses =
              defined( _ARRAY( $pluginTables{$pluginTable} ) )
              ? @{ $pluginTables{$pluginTable} }
              : ( $pluginTables{$pluginTable} );

            if ( exists( $self->{tables2classes}->{$pte} ) )
            {
                defined( _ARRAY( $self->{tables2classes}->{$pte} ) )
                  or $self->{tables2classes}->{$pte} = [ $self->{tables2classes}->{$pte} ];

                push(



( run in 0.960 second using v1.01-cache-2.11-cpan-39bf76dae61 )