ActionPack.pm

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