File Coverage

blib/lib/Aspect/Pointcut/Throwing.pm
Criterion Covered Total %
statement 32 39 82.0
branch 1 6 16.6
condition n/a
subroutine 12 12 100.0
pod 3 3 100.0
total 48 60 80.0


line stmt bran cond sub pod time code
1             package Aspect::Pointcut::Throwing;
2              
3 21     21   84 use strict;
  21         24  
  21         588  
4 21     21   80 use warnings;
  21         27  
  21         462  
5 21     21   80 use Carp ();
  21         28  
  21         266  
6 21     21   73 use Params::Util ();
  21         22  
  21         301  
7 21     21   74 use Aspect::Pointcut ();
  21         31  
  21         250  
8 21     21   79 use Aspect::Pointcut::Not ();
  21         24  
  21         297  
9 21     21   8173 use Aspect::Pointcut::Returning ();
  21         37  
  21         5746  
10              
11             our $VERSION = '0.97_06';
12             our @ISA = 'Aspect::Pointcut';
13              
14              
15              
16              
17              
18             ######################################################################
19             # Constructor
20              
21             sub new {
22 16     16 1 36 my $class = shift;
23 16         26 my $spec = shift;
24              
25             # Handle the any exception case
26 16 50       55 unless ( defined $spec ) {
27 16         106 return bless [
28             $spec,
29             "\$_->{exception}",
30             ], $class;
31             }
32              
33             # Handle a specific die message
34 0 0       0 if ( Params::Util::_STRING($spec) ) {
35 0         0 return bless [
36             $spec,
37             "Params::Util::_INSTANCE(\$_->{exception}, '$spec')",
38             ], $class;
39             }
40              
41             # Handle a specific exception class
42 0 0       0 if ( Params::Util::_REGEX($spec) ) {
43 0         0 my $regex = "/$spec/";
44 0         0 $regex =~ s|^/\(\?([xism]*)-[xism]*:(.*)\)/\z|/$2/$1|s;
45 0         0 return bless [
46             $spec,
47             "defined \$_->{exception} and not ref \$_->{exception} and \$_->{exception} =~ $regex",
48             ], $class;
49             }
50              
51 0         0 Carp::croak("Invalid throwing pointcut specification");
52             }
53              
54              
55              
56              
57              
58             ######################################################################
59             # Weaving Methods
60              
61             # Exception pointcuts always match at weave time and should curry away
62             sub curry_weave {
63 16     16 1 36 return;
64             }
65              
66             # Throwing pointcuts do not curry.
67             # (But maybe they should, when used with say a before {} block)
68             sub curry_runtime {
69 16     16 1 50 return $_[0];
70             }
71              
72             sub compile_runtime {
73             $_[0]->[1];
74             }
75              
76              
77              
78              
79              
80             ######################################################################
81             # Optional XS Acceleration
82              
83             BEGIN {
84 21     21   39 local $@;
85 21     21   1671 eval <<'END_PERL';
  21         103  
  21         435  
  21         190  
86             use Class::XSAccessor::Array 1.08 {
87             replace => 1,
88             getters => {
89             'compile_runtime' => 1,
90             },
91             };
92             END_PERL
93             }
94              
95             1;
96              
97             __END__