| 1 | package Business::BancaSella::Ric; | ||
| 2 | |||
| 3 | $VERSION = "0.11"; | ||
| 4 | sub Version { $VERSION; } | ||
| 5 | |||
| 6 | require 5.004; | ||
| 7 | use strict; | ||
| 8 | use warnings; | ||
| 9 | use Carp; | ||
| 10 | |||
| 11 | use Business::BancaSella::Ric::File; | ||
| 12 | use Business::BancaSella::Ris::FileFast; | ||
| 13 | use Business::BancaSella::Ric::Mysql; | ||
| 14 | |||
| 15 | my %fields = | ||
| 16 | ( | ||
| 17 | type => 'file', | ||
| 18 | ); | ||
| 19 | |||
| 20 | my @fields_req = qw/type/; | ||
| 21 | |||
| 22 | |||
| 23 | sub new | ||
| 24 | { | ||
| 25 | my $proto = shift; | ||
| 26 | my $class = ref($proto) || $proto; | ||
| 27 | my $self = {}; | ||
| 28 | bless $self,$class; | ||
| 29 | $self->init(@_); | ||
| 30 | return $self; | ||
| 31 | } | ||
| 32 | |||
| 33 | sub init { | ||
| 34 | my $self = shift; | ||
| 35 | my (%options) = @_; | ||
| 36 | # Assign default options | ||
| 37 | while (my ($key,$value) = each(%fields)) { | ||
| 38 | $self->{$key} = $self->{$key} || $value; | ||
| 39 | } | ||
| 40 | # Assign options | ||
| 41 | while (my ($key,$value) = each(%options)) { | ||
| 42 | $self->{$key} = $value | ||
| 43 | } | ||
| 44 | # Check required params | ||
| 45 | foreach (@fields_req) { | ||
| 46 | croak "You must declare '$_' in " . ref($self) . "::new" | ||
| 47 | if (!defined $self->{$_}); | ||
| 48 | } | ||
| 49 | if ($self->type eq 'file') { | ||
| 50 | no strict 'vars'; | ||
| 51 | unshift @ISA,'Business::BancaSella::Ric::File'; | ||
| 52 | } elsif ($self->type eq 'mysql') { | ||
| 53 | no strict 'vars'; | ||
| 54 | unshift @ISA,'Business::BancaSella::Ric::Mysql'; | ||
| 55 | } elsif ($self->type eq 'filefast') { | ||
| 56 | no strict 'vars'; | ||
| 57 | unshift @ISA,'Business::BancaSella::Ric::FileFast'; | ||
| 58 | } else { | ||
| 59 | die "Unsupported type " . $self->type . "in " . ref($self) . "::new"; | ||
| 60 | } | ||
| 61 | $self->SUPER::init(@_); | ||
| 62 | } | ||
| 63 | |||
| 64 | sub type { my $s=shift; return @_ ? ($s->{type}=shift) : $s->{type} } | ||
| 65 | |||
| 66 | 1; | ||
| 67 | __END__ |