Die-Hard
view release on metacpan or search on metacpan
lib/Die/Hard.pm view on Meta::CPAN
my $r;
$self->_set_last_error($@)
unless eval { $r = $self->proxy_for->$coderef(@_); 1 };
return $r;
}
else
{
$self->_set_last_error($@)
unless eval { $self->proxy_for->$coderef(@_); 1 };
return;
}
}
sub can
{
my ($self, $method) = @_;
return $self->SUPER::can($method) unless Scalar::Util::blessed($self);
my $i_can = $self->SUPER::can($method);
my $he_can = $self->proxy_for->can($method);
return $i_can if $i_can;
return sub { our $AUTOLOAD = $method; goto \&AUTOLOAD } if $he_can;
return;
}
sub DOES
{
my ($self, $role) = @_;
return $self->SUPER::DOES($role) unless Scalar::Util::blessed($self);
$self->SUPER::DOES($role) or $self->proxy_for->DOES($role);
}
sub isa
{
my ($self, $role) = @_;
return $self->SUPER::isa($role) unless Scalar::Util::blessed($self);
$self->SUPER::isa($role) or $self->proxy_for->isa($role);
}
no Moo;
1;
__END__
=head1 NAME
Die::Hard - objects as resistant to dying as John Maclane
=head1 SYNOPSIS
my $fragile = Fragile::Object->new;
my $diehard = Die::Hard->new($fragile);
$diehard->isa('Fragile::Object'); # true
$diehard->method_that_will_die; # lives!
$fragile->method_that_will_die; # dies!
=head1 DESCRIPTION
Die::Hard allows you to create fairly transparent wrapper object that
delegates all method calls through to the wrapped object, but does so
within an C<< eval { ... } >> block. If the wrapped method call dies,
then it sets a C<< last_error >> attribute.
=head2 Constructor
=over
=item C<< new(%attributes) >>
Standard Moose-style constructor.
=item C<< new($object) >>
Shortcut for setting the C<proxy_for> attribute.
=back
=head2 Attributes
=over
=item C<< proxy_for >>
The object being wrapped. Read-only; required.
=item C<< last_error >>
If the last proxied method call died, then this attribute will contain
the error. Otherwise will be undef.
=back
=head2 Methods
=over
=item C<< isa >>
Tells lies; claims to be the object it's proxying.
=item C<< DOES >>
Tells the truth; claims to do the object it's proxying.
=item C<< can >>
Tells the truth; claims it can do anything the object it's proxying can do.
=back
=begin private
=item AUTOLOAD
=item BUILDARGS
=end private
=head1 BUGS
( run in 0.622 second using v1.01-cache-2.11-cpan-98e64b0badf )