| 1 | package Exception::Delayed; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | # ABSTRACT: Execute code and throw exceptions later | ||||||||||||||
| 4 | |||||||||||||||
| 5 | 3 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | 3 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | |||||||||||||||
| 8 | 3 | our $VERSION = '0.001'; # VERSION | |||||||||||||
| 9 | |||||||||||||||
| 10 | sub wantscalar { | ||||||||||||||
| 11 | 2 | ▶ | my ( $class, $code, @args ) = @_; | ||||||||||||
|
Subroutine
wantscalar: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||
| 12 | 2 | my $RV; | |||||||||||||
| 13 | 2 | eval { $RV = scalar $code->(@args); }; | |||||||||||||
| 14 | 2 | ▶ | if ($@) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 15 | 1 | return bless { error => $@ } => $class; | |||||||||||||
| 16 | } | ||||||||||||||
| 17 | else { | ||||||||||||||
| 18 | 1 | return bless { result => \$RV } => $class; | |||||||||||||
| 19 | } | ||||||||||||||
| 20 | } | ||||||||||||||
| 21 | |||||||||||||||
| 22 | sub wantlist { | ||||||||||||||
| 23 | 1 | ▶ | my ( $class, $code, @args ) = @_; | ||||||||||||
|
Subroutine
wantlist: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||
| 24 | 1 | my @RV; | |||||||||||||
| 25 | 1 | eval { @RV = $code->(@args); }; | |||||||||||||
| 26 | 1 | ▶ | if ($@) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 27 | 0 | return bless { error => $@ } => $class; | |||||||||||||
| 28 | } | ||||||||||||||
| 29 | else { | ||||||||||||||
| 30 | 1 | return bless { result => \@RV } => $class; | |||||||||||||
| 31 | } | ||||||||||||||
| 32 | } | ||||||||||||||
| 33 | |||||||||||||||
| 34 | sub result { | ||||||||||||||
| 35 | 3 | ▶ | my ($self) = @_; | ||||||||||||
|
Subroutine
result: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||
| 36 | 3 | ▶ | if ( exists $self->{error} ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 37 | 1 | die $self->{error}; | |||||||||||||
| 38 | } | ||||||||||||||
| 39 | else { | ||||||||||||||
| 40 | 2 | my $result = delete $self->{result}; | |||||||||||||
| 41 | 2 | ▶ | if ( ref $result eq 'ARRAY' ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 42 | 1 | return @$result; | |||||||||||||
| 43 | } | ||||||||||||||
| 44 | elsif ( ref $result eq 'SCALAR' ) { | ||||||||||||||
| 45 | 1 | return $$result; | |||||||||||||
| 46 | } | ||||||||||||||
| 47 | else { | ||||||||||||||
| 48 | 0 | return; | |||||||||||||
| 49 | } | ||||||||||||||
| 50 | } | ||||||||||||||
| 51 | } | ||||||||||||||
| 52 | |||||||||||||||
| 53 | 3 | 1; | |||||||||||||
| 54 | |||||||||||||||
| 55 | __END__ | ||||||||||||||