ActionPack.pm

filter: Statementstmt 88.4% 46 / 52 Branchbran 68.1% 15 / 22 Conditioncond 44.4% 4 / 9 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 80.0% 12 / 15 Podpod 87.5% 7 / 8 totaltotal 76.5% 85 / 111 CC 16 SCAR 13.9
CC
16
Cov
78%
inflate
7.0
has_mapping
6.0
create
5.4
CRAP 4.0
« ActionPack/ContentNegotiation.pm ↑ Summary ActionPack/MediaType.pm »
1 package HTTP::Headers::ActionPack;
2 # ABSTRACT: HTTP Action, Adventure and Excitement
3  
4 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 9 our $VERSION = '0.10';
8  
9 9 ▶use Scalar::Util qw[ blessed ];
Subroutine BEGIN: called CC=1 SCAR=0.0
10 9 ▶use Carp qw[ confess ];
Subroutine BEGIN: called CC=1 SCAR=0.0
11 9 ▶use Module::Runtime qw[ use_module ];
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 9 my @DEFAULT_CLASSES = qw[
14 HTTP::Headers::ActionPack::AcceptCharset
15 HTTP::Headers::ActionPack::AcceptLanguage
16 HTTP::Headers::ActionPack::AuthenticationInfo
17 HTTP::Headers::ActionPack::Authorization
18 HTTP::Headers::ActionPack::Authorization::Basic
19 HTTP::Headers::ActionPack::Authorization::Digest
20 HTTP::Headers::ActionPack::DateHeader
21 HTTP::Headers::ActionPack::LinkHeader
22 HTTP::Headers::ActionPack::LinkList
23 HTTP::Headers::ActionPack::MediaType
24 HTTP::Headers::ActionPack::MediaTypeList
25 HTTP::Headers::ActionPack::PriorityList
26 HTTP::Headers::ActionPack::WWWAuthenticate
27 ];
28  
29 9 my %DEFAULT_MAPPINGS = (
30 'link' => 'HTTP::Headers::ActionPack::LinkList',
31 'content-type' => 'HTTP::Headers::ActionPack::MediaType',
32 'accept' => 'HTTP::Headers::ActionPack::MediaTypeList',
33 'accept-charset' => 'HTTP::Headers::ActionPack::AcceptCharset',
34 'accept-encoding' => 'HTTP::Headers::ActionPack::PriorityList',
35 'accept-language' => 'HTTP::Headers::ActionPack::AcceptLanguage',
36 'date' => 'HTTP::Headers::ActionPack::DateHeader',
37 'client-date' => 'HTTP::Headers::ActionPack::DateHeader', # added by LWP
38 'expires' => 'HTTP::Headers::ActionPack::DateHeader',
39 'last-modified' => 'HTTP::Headers::ActionPack::DateHeader',
40 'if-unmodified-since' => 'HTTP::Headers::ActionPack::DateHeader',
41 'if-modified-since' => 'HTTP::Headers::ActionPack::DateHeader',
42 'www-authenticate' => 'HTTP::Headers::ActionPack::WWWAuthenticate',
43 'authentication-info' => 'HTTP::Headers::ActionPack::AuthenticationInfo',
44 'authorization' => 'HTTP::Headers::ActionPack::Authorization',
45 );
46  
47 9 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
48 9 my $class = shift;
49 9 my %additional = @_;
50 9 my %mappings = ( %DEFAULT_MAPPINGS, %additional );
51 9 my %classes = map { $_ => undef } ( @DEFAULT_CLASSES, values %additional );
52  
53 9 bless {
54 mappings => \%mappings,
55 classes => \%classes
56 } => $class;
57 }
58  
59 0 ▶sub mappings { (shift)->{'mappings'} }
Subroutine mappings: not called CC=1 SCAR=6.9
Pod documented
60 0 ▶sub classes { keys %{ (shift)->{'classes'} } }
Subroutine classes: not called CC=1 SCAR=6.9
Pod documented
61  
62 0 ▶sub has_mapping {
Subroutine has_mapping: not called CC=2 SCAR=17.9
Pod undocumented
63 0 my ($self, $header_name) = @_;
64 0 ▶ exists $self->{'mappings'}->{ lc $header_name } ? 1 : 0
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'mappings'}{lc $header_name} ? : 0 0 0
65 }
66  
67 4 ▶sub get_content_negotiator {
Subroutine get_content_negotiator: called CC=1 SCAR=0.0
Pod documented
68 4 use_module('HTTP::Headers::ActionPack::ContentNegotiation')->new( shift );
69 }
70  
71 102 ▶sub create {
Subroutine create: called CC=5 SCAR=16.8
Pod documented
72 102 my ($self, $class_name, $args) = @_;
73  
74 my $class = exists $self->{'classes'}->{ $class_name }
75 ? $class_name
76 102 ▶ : exists $self->{'classes'}->{ __PACKAGE__ . '::' . $class_name }
Branch: 2 branches
BranchTrueFalseTotal
exists $self->{'classes'}{$class_name} ? : 0 102 102
exists $self->{'classes'}{'HTTP::Headers::ActionPack::' . $class_name} ? : 102 0 102
77 ? __PACKAGE__ . '::' . $class_name
78 : undef;
79  
80 102 ▶ (defined $class)
Branch: 1 branch
BranchTrueFalseTotal
defined $class or confess("Could not find class '${class_name}' (or 'HTTP::Headers::ActionPack::${class_name}')") 102 0 102
81 || confess "Could not find class '$class_name' (or 'HTTP::Headers::ActionPack::$class_name')";
82  
83 102 ▶ ref $args
Branch: 1 branch
BranchTrueFalseTotal
ref $args ? : 10 92 102
84 ? use_module( $class )->new( @$args )
85 : use_module( $class )->new_from_string( $args );
86 }
87  
88 17 ▶sub create_header {
Subroutine create_header: called CC=3 SCAR=11.0
Pod documented
89 17 my ($self, $header_name, $header_value) = @_;
90  
91 17 my $class = $self->{'mappings'}->{ lc $header_name };
92  
93 17 ▶ (defined $class)
Branch: 1 branch
BranchTrueFalseTotal
defined $class or confess("Could not find mapping for '${header_name}'") 17 0 17
94 || confess "Could not find mapping for '$header_name'";
95  
96 17 ▶ ref $header_value
Branch: 1 branch
BranchTrueFalseTotal
ref $header_value ? : 4 13 17
97 ? use_module( $class )->new( @$header_value )
98 : use_module( $class )->new_from_string( $header_value );
99 }
100  
101 4 ▶sub inflate {
Subroutine inflate: called CC=5 SCAR=19.4
Pod documented
102 4 my $self = shift;
103 4 ▶ return $self->_inflate_http_headers( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]->isa("HTTP::Headers") 3 1 4
104 if $_[0]->isa('HTTP::Headers');
105 1 ▶ return $self->_inflate_generic_request( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]->isa("HTTP::Request") or $_[0]->isa("Plack::Request") or $_[0]->isa("Web::Request") 1 0 1
Condition33%2/6
$_[0]->isa("HTTP::Request") or $_[0]->isa("Plack::Request") or $_[0]->isa("Web::Request")
l!l&&r!l&&!r
100
$_[0]->isa("HTTP::Request") or $_[0]->isa("Plack::Request")
l!l&&r!l&&!r
100
MC/DC0%0/3
$_[0]->isa("HTTP::Request") or $_[0]->isa("Plack::Request") or $_[0]->isa("Web::Request")
$_[0]->isa("HTTP::Request") $_[0]->isa("Plack::Request") $_[0]->isa("Web::Request")
Truth table25%1/4
A or B or C
A= $_[0]->isa("HTTP::Request")B= $_[0]->isa("Plack::Request")C= $_[0]->isa("Web::Request")
ABCresult
1XX1
01X1
0011
0000
106 if $_[0]->isa('HTTP::Request')
107 || $_[0]->isa('Plack::Request')
108 || $_[0]->isa('Web::Request');
109 0 confess "I don't know how to inflate '$_[0]'";
110 }
111  
112 4 ▶sub _inflate_http_headers {
Subroutine _inflate_http_headers: called CC=5 SCAR=16.1
113 4 my ($self, $http_headers) = @_;
114 4 foreach my $header ( keys %{ $self->{'mappings'} } ) {
115 60 ▶ if ( my $old = $http_headers->header( $header ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $old = $http_headers->header($header)) 8 52 60
116 8 ▶ $http_headers->header( $header => $self->create_header( $header, $old ) )
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($old) and $old->isa("HTTP::Headers::ActionPack::Core::Base") 7 1 8
Condition66%2/3
builtin::blessed($old) and $old->isa("HTTP::Headers::ActionPack::Core::Base")
!ll&&!rl&&r
701
MC/DC50%1/2
builtin::blessed($old) and $old->isa("HTTP::Headers::ActionPack::Core::Base")
builtin::blessed($old) $old->isa("HTTP::Headers::ActionPack::Core::Base")
Truth table66%2/3
A and B
A= builtin::blessed($old)B= $old->isa("HTTP::Headers::ActionPack::Core::Base")
ABresult
0X0
100
111
117 unless blessed $old && $old->isa('HTTP::Headers::ActionPack::Core::Base');
118 }
119 }
120 4 return $http_headers;
121 }
122  
123 1 ▶sub _inflate_generic_request {
Subroutine _inflate_generic_request: called CC=1 SCAR=0.0
124 1 my ($self, $request) = @_;
125 1 $self->_inflate_http_headers( $request->headers );
126 1 return $request;
127 }
128  
129 9 1;
130  
131 __END__
« ActionPack/ContentNegotiation.pm ↑ Summary ActionPack/MediaType.pm »