Data-Fallback
view release on metacpan or search on metacpan
Fallback.pm view on Meta::CPAN
$accept_update = $self->{hash}{accept_update};
} elsif( (defined $self->{accept_update}) && length $self->{accept_update}) {
$accept_update = $self->{accept_update};
}
return $accept_update;
}
sub list_update {
my $self = shift;
my $i = shift;
for(my $j=($i - 1);$j>=0;$j--) {
$self->{hash} = $self->{list}[$j];
my $accept_update = $self->get_accept_update;
next unless($accept_update);
my $delete_hash_primary_key;
if(!exists $self->{hash}{primary_key} && exists $self->{set_primary_key}) {
$self->{hash}{primary_key} = $self->{set_primary_key};
}
if(!ref $accept_update) {
$self->_list_update_helper($accept_update);
} else {
if(ref $accept_update eq 'ARRAY') {
for(my $i=0;$i<@{$accept_update};$i++) {
my $this_update = $accept_update->[$i];
if(ref $this_update) {
if(ref $this_update eq 'Regexp') {
if($self->{got_item_from} && $self->{got_item_from} =~ /$this_update/) {
if($accept_update->[($i + 1)]) {
$self->_list_update_helper($accept_update->[($i + 1)]);
}
}
} elsif(ref $this_update eq 'CODE') {
my $return = &{$this_update}($self);
$self->_list_update_helper($return);
}
}
}
}
}
delete $self->{hash}{primary_key} if($delete_hash_primary_key);
}
}
sub _list_update_helper {
my $self = shift;
my $update_type = shift;
if($update_type eq 'item') {
$self->update_item;
} elsif($update_type eq 'group') {
$self->update_group;
} elsif($update_type eq 'all') {
$self->update_item;
$self->update_group;
} else {
confess "unknown \$update_type: $update_type";
}
}
sub update_item {
my $self = shift;
if(exists $self->{update}{item}) {
$self->morph($self->{hash}{package});
$self->SET_ITEM;
}
}
sub update_group {
my $self = shift;
if( (defined $self->{update}{item}) && length $self->{update}{item}) {
$self->morph($self->{hash}{package});
$self->SET_GROUP;
}
}
sub set_list_name {
my $self = shift;
my $list_name = shift || die "need a list_name";
$self->{list_name} = $list_name;
}
sub set_list {
my $self = shift;
my $list = shift;
die "need a list" unless($list);
die "list needs to be an ARRAY ref" unless(ref $list && ref $list eq 'ARRAY');
$self->{list} = $list;
}
sub INITIALIZE_PACKAGE {
return;
}
### this turns the object into the correct type
### thanks to Paul Seamons for the start of this code
sub morph {
my $self = shift;
my $package = shift;
my $tmp_package = $package;
$tmp_package =~ s@::@/@g;
### polymorph
my $at = '';
# this little trick should allow users to write their own overriding
# fallback methods, thanks to Rob Brown for the idea
if($tmp_package =~ m@/@) {
eval {
require "$tmp_package.pm";
};
if($@) {
$at .= $@;
} else {
bless $self, $package;
}
} else {
# likely a Data::Fallback package
eval {
require "Data/Fallback/$tmp_package.pm";
};
if( $@ ){
$at .= $@;
# this is just for sort of top level stuff like CGI
eval {
require "$tmp_package.pm";
};
( run in 1.214 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )