ResponseHelper.pm

filter: Statementstmt 95.1% 39 / 41 Branchbran 66.6% 8 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 90.1% 55 / 61 CC 8 SCAR 12.2
CC
8
Cov
89%
import
5.0
respond
4.3
BEGIN
1.0
CRAP 3.4
↑ Summary ResponseHelper/Text.pm »
1 package Plack::ResponseHelper;
2 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 6 our $HELPERS = {};
7  
8 6 ▶sub import {
Subroutine import: called CC=5 SCAR=16.1
9 6 shift;
10 6 my %options = @_;
11 6 foreach my $type (keys %options) {
12 my ($helper, $init) = ref $options{$type}
13 2 ? @{$options{$type}}
14 5 ▶ : ($options{$type}, undef);
Branch: 1 branch
BranchTrueFalseTotal
ref $options{$type} ? : 2 3 5
15  
16 5 $helper =~ s/^\+//;
17 5 ▶ croak "bad helper name $helper" unless $helper =~ /^\w+(?:::\w+)*$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $helper =~ /^\w+(?:::\w+)*$/ 0 5 5
18  
19 5 my $package = "Plack::ResponseHelper::$helper";
20 5 ▶ eval "require $package" or croak $@;
Branch: 1 branch
BranchTrueFalseTotal
eval "require $package" or croak($@) 5 0 5
21  
22 6 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
23 5 my $code = *{$package.'::helper'}->($init);
24 5 $HELPERS->{$type} = $code;
25 }
26  
27 6 my $pkg = caller;
28 6 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
29 6 *{$pkg.'::respond'} = \&respond;
30 }
31  
32 9 ▶sub respond {
Subroutine respond: called CC=4 SCAR=14.6
Pod documented
33 9 my $type = shift;
34 9 my $r = shift;
35  
36 9 ▶ croak "unknown type '$type'" unless exists $HELPERS->{$type};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $Plack::ResponseHelper::HELPERS->{$type} 1 8 9
37 8 $r = $HELPERS->{$type}->($r);
38  
39 7 ▶ if (ref $r =~ /^(?:ARRAY|CODE)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $r =~ /^(?:ARRAY|CODE)$/) 0 7 7
40 0 return $r;
41 }
42 7 ▶ if (UNIVERSAL::isa($r, "Plack::Response")) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($r, "Plack::Response")) 7 0 7
43 7 return $r->finalize();
44 }
45  
46 0 croak "bad response";
47 }
48  
49 6 1;
50 __END__
↑ Summary ResponseHelper/Text.pm »