Ambrosia

 view release on metacpan or  search on metacpan

lib/Ambrosia/DataProvider.pm  view on Meta::CPAN

    $self->_list->{$_} = $list{$_} foreach ( keys %list);
}

sub driver #(driverType, sourceName)
{
    assert {$_[0] && $_[1] && $_[2]} "bad usage: driver(@_)";
    shift()->_list->{+shift}->{+shift};
}

sub foreach
{
    my $self = shift;
    my $function = shift;
    foreach my $type ( keys %{$self->_list} )
    {
        foreach my $name ( keys %{$self->_list->{$type}} )
        {
            if ( ref $function )
            {
                $function->($self->_list->{$type}->{$name}, $type, $name, @_);
            }
            else
            {
                if ( $self->_list->{$type}->{$name}->can($function) )
                {
                    $self->_list->{$type}->{$name}->$function(@_);
                }
                else
                {
                    croak("Unknown method $function in driver $name of type $type");
                }
            }
        }
    }
}

1;

__END__

=head1 NAME

Ambrosia::DataProvider - a container for data sources. (Singleton)

=head1 VERSION

version 0.010

=head1 SYNOPSIS

    use Ambrosia::DataProvider;
    my $confDS = {
        DBI => [
            {
                engine_name   => 'DB::mysql',
                source_name  => 'Employee',
                engine_params => 'database=EmployeeDB;host=localhost;',
                user         => 'test',
                password     => 'test',
                additional_params => { AutoCommit => 0, RaiseError => 1, LongTruncOk => 1 },
                additional_action => sub { my $dbh = shift; $dbh->do('SET NAMES utf8')},
            },
            #........
        ],
        IO => [
            {
                engine_name => 'IO::CGI',
                source_name => 'cgi',
                engine_params => {
                    header_params => {
                            '-Pragma' => 'no-cache',
                            '-Cache_Control' => 'no-cache, must-revalidate, no-store'
                        }
                    }
            }
        ],
        
    };

    instance Ambrosia::Storage(application_name => $confDS);
    Ambrosia::DataProvider::assign 'application_name';


=head1 DESCRIPTION

Ambrosia::DataProvider is a container for data sources. (Singleton)

For more information see:

=over

=item L<Ambrosia::DataProvider::DBIDriver>

=item L<Ambrosia::DataProvider::IODriver>

=item L<Ambrosia::DataProvider::ResourceDriver>

=back

=head1 SUBROUTINES/METHODS

=head2 instance

Static subrutine.
Creates a singleton container.

    instance('storage_name' => $config_data)

    Structure of config data:

    config = {
        DRIVER_TYPE => [
                engine_name   => 'ENGINE_FOR_DRIVER_TYPE',
                source_name  => 'UNIQ_NAME_FOR_SOURCE_DATA',
                engine_params => 'PARAMS_FOR_ENGINE',
                %ANY_ADDITIONAL_PARAMS_FOR_DRIVER_TYPE
        ]
    }

=head2 assign



( run in 2.939 seconds using v1.01-cache-2.11-cpan-5837b0d9d2c )