blib/lib/MasonX/Interp/WithCallbacks.pm

filter: Statementstmt 98.3% 58 / 59 Branchbran 100% 10 / 10 Conditioncond 50.0% 3 / 6 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 91.6% 11 / 12 Podpod 100% 3 / 3 totaltotal 92.4% 86 / 93 SCAR 22.0
CC
9
Cov
95%
make_request
5.0
__ANON__
3.0
new
3.0
CRAP 9.0
↑ Summary Build »
1 package MasonX::Interp::WithCallbacks;
2  
3 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use HTML::Mason qw(1.23);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 ▶use HTML::Mason::Interp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 8 ▶use HTML::Mason::Exceptions ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 8 ▶use Params::CallbackRequest;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 8 ▶use vars qw($VERSION @ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 8 @ISA = qw(HTML::Mason::Interp);
11 8 $VERSION = '1.19';
12  
13 Params::Validate::validation_options
14 0 ▶ ( on_fail => sub { HTML::Mason::Exception::Params->throw( join '', @_ ) } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
15  
16  
17 use HTML::Mason::MethodMaker(
18 8 read_only => [qw(cb_request)],
19 read_write => [qw(comp_path)],
20 8 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 # We'll use this code reference to eval arguments passed in via httpd.conf
23 # PerlSetVar directives.
24 my $eval_directive = { convert => sub {
25 17 ▶ return 1 if ref $_[0]->[0];
Subroutine __ANON__: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0][0] 16 1 17
26 1 for (@{$_[0]}) { $_ = eval $_ }
27 1 return 1;
28 8 }};
29  
30 8 __PACKAGE__->valid_params
31 ( default_priority =>
32 { type => Params::Validate::SCALAR,
33 parse => 'string',
34 default => 5,
35 descr => 'Default callback priority'
36 },
37  
38 default_pkg_key =>
39 { type => Params::Validate::SCALAR,
40 parse => 'string',
41 default => 'DEFAULT',
42 descr => 'Default package key'
43 },
44  
45 callbacks =>
46 { type => Params::Validate::ARRAYREF,
47 parse => 'list',
48 optional => 1,
49 callbacks => $eval_directive,
50 descr => 'Callback specifications'
51 },
52  
53 pre_callbacks =>
54 { type => Params::Validate::ARRAYREF,
55 parse => 'list',
56 optional => 1,
57 callbacks => $eval_directive,
58 descr => 'Callbacks to be executed before argument callbacks'
59 },
60  
61 post_callbacks =>
62 { type => Params::Validate::ARRAYREF,
63 parse => 'list',
64 optional => 1,
65 callbacks => $eval_directive,
66 descr => 'Callbacks to be executed after argument callbacks'
67 },
68  
69 cb_classes =>
70 { type => Params::Validate::ARRAYREF | Params::Validate::SCALAR,
71 parse => 'list',
72 optional => 1,
73 descr => 'List of calback classes from which to load callbacks'
74 },
75  
76 ignore_nulls =>
77 { type => Params::Validate::BOOLEAN,
78 parse => 'boolean',
79 default => 0,
80 descr => 'Execute callbacks with null values'
81 },
82  
83 cb_exception_handler =>
84 { type => Params::Validate::CODEREF,
85 parse => 'code',
86 optional => 1,
87 descr => 'Callback execution exception handler'
88 },
89 );
90  
91  
92 sub new {
93 20 ▶ my $class = shift;
Subroutine new: called CC=3 SCAR=11.0
Pod documented
94 20 my $self = $class->SUPER::new(@_);
95 # This causes everything to be validated twice, but it shouldn't matter
96 # much, since interp objects won't be created very often.
97 20 my $exh = delete $self->{cb_exception_handler};
98 $self->{cb_request} = Params::CallbackRequest->new
99 ( leave_notes => 1,
100 ($exh ? (exception_handler => $exh) : ()),
101 160 ▶ map { $self->{$_} ? ($_ => delete $self->{$_}) : () }
Branch: 1 branch
BranchTrueFalseTotal
$self->{$_} ? : 64 96 160
102 20 ▶ keys %{ __PACKAGE__->valid_params }
Branch: 1 branch
BranchTrueFalseTotal
$exh ? : 2 18 20
103 );
104 15 $self;
105 }
106  
107 sub make_request {
108 112 ▶ my ($self, %p) = @_;
Subroutine make_request: called CC=5 SCAR=16.2
Pod documented
109 # We have to grab the parameters and copy them into a hash.
110 112 my %params = @{$p{args}};
111 112 $self->{comp_path} = $p{comp};
112  
113 # Grab the apache request object, if it exists.
114 my $apache_req = $p{apache_req}
115 112 ▶ || $self->delayed_object_params('request', 'apache_req')
Condition50%3/6
$p{'apache_req'} || $self->delayed_object_params('request', 'apache_req') || $self->delayed_object_params('request', 'cgi_request')
l!l&&r!l&&!r
05107
$p{"apache_req"} or $self->delayed_object_params("request", "apache_req")
l!l&&r!l&&!r
00112
MC/DC33%1/3
$p{'apache_req'} || $self->delayed_object_params('request', 'apache_req') || $self->delayed_object_params('request', 'cgi_request')
$p{"apache_req"} $self->delayed_object_params("request", "apache_req") $self->delayed_object_params('request', 'cgi_request')
Truth table50%2/4
A or B || C
A= $p{"apache_req"}B= $self->delayed_object_params("request", "apache_req")C= $self->delayed_object_params('request', 'cgi_request')
ABCresult
1XX1
01X1
0011
0000
116 || $self->delayed_object_params('request', 'cgi_request');
117  
118 # Execute the callbacks.
119 my $ret = $self->{cb_request}->request(
120 112 ▶ \%params,
Branch: 1 branch
BranchTrueFalseTotal
$apache_req ? : 5 107 112
121 requester => $self,
122 $apache_req ? ( apache_req => $apache_req ) : (),
123 );
124  
125 # Abort the request if that's what the callbacks want.
126 102 ▶ unless (ref $ret) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $ret) 7 95 102
127 7 $self->{cb_request}->clear_notes;
128 7 HTML::Mason::Exception::Abort->throw(
129 error => 'Callback->abort was called',
130 aborted_value => $ret,
131 );
132 }
133  
134 # Copy the parameters back -- too much copying!
135 95 $p{args} = [%params];
136 95 $p{comp} = $self->{comp_path};
137  
138 # Get the request, copy the notes, and continue.
139 95 my $req = $self->SUPER::make_request(%p);
140 # Should I use the same reference?
141 94 %{$req->notes} = %{$self->{cb_request}->notes};
142 94 return $req;
143 }
144  
145 # We override this method in order to clear out all the callback notes
146 # at the end of the Mason request.
147 sub purge_code_cache {
148 95 ▶ my $self = shift;
Subroutine purge_code_cache: called CC=1 SCAR=0.0
Pod documented
149 95 $self->{cb_request}->clear_notes;
150 95 $self->SUPER::purge_code_cache;
151 }
152  
153 8 1;
154 __END__
↑ Summary Build »