If i understand you correctly, it's the "Factory method" pattern case. I'm using it for storage abstraction.
package Storage::Factory; { use Storage::SQLite; use Storage::MySQL; sub new { my $class = shift; my $opt = {@_}; return Storage::SQLite->new(file => $opt->{dsn}) if $opt->{typ +e} eq 'sqlite'; return Storage::MySQL->new(dsn => $opt->{dsn}) if $opt->{type} + eq 'mysql'; } } 1; use Storage::Factory; my $storage = Storage::Factory->new(%{ $self->plugin('Config')->{db} } +)
|
|---|