blib/lib/CGI/Application/Plugin/Header.pm

filter: Statementstmt 98.3% 59 / 60 Branchbran 93.3% 28 / 30 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 11 / 11 Podpod 75.0% 3 / 4 totaltotal 93.6% 103 / 110 CC 17 SCAR 15.0
CC
17
Cov
96%
header_add
8.0
header_props
5.0
BUILD
4.1
CRAP 4.5
↑ Summary
1 package CGI::Application::Plugin::Header;
2 7 ▶use 5.008_009;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 ▶use parent 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 7 ▶use CGI::Header;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 7 ▶use Carp qw/carp croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 7 our $VERSION = '0.63008';
10 7 our @EXPORT = qw( header header_add header_props );
11  
12 6 ▶sub import {
Subroutine import: called CC=1 SCAR=0.0
13 6 my ( $class ) = @_;
14 6 my $caller = caller;
15 6 $caller->add_callback( init => \&BUILD );
16 6 $class->export_to_level( 1, @_ );
17 }
18  
19 28 ▶sub BUILD {
Subroutine BUILD: called CC=4 SCAR=14.0
Pod undocumented
20 28 my $self = shift;
21 0 ▶ my @args = ref $_[0] eq 'HASH' ? %{$_[0]} : @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 28 28
22  
23 28 ▶ while ( my ($key, $value) = splice @args, 0, 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@args, 0, 2)) 13 28 41
24 13 ▶ $self->{+__PACKAGE__} = $value if lc $key eq 'header';
Branch: 1 branch
BranchTrueFalseTotal
if lc $key eq "header" 1 12 13
25 }
26  
27 28 return;
28 }
29  
30 122 ▶sub header {
Subroutine header: called CC=3 SCAR=11.0
Pod documented
31 122 my $self = shift;
32 122 ▶ return $self->{+__PACKAGE__} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 9 113 122
33 113 ▶ $self->{+__PACKAGE__} ||= CGI::Header->new( query => $self->query );
Condition66%2/3
$self->{"CGI::Application::Plugin::Header"} ||= "CGI::Header"->new("query", $self->query)
l!l&&r!l&&!r
94190
MC/DC0%0/2
$self->{"CGI::Application::Plugin::Header"} ||= "CGI::Header"->new("query", $self->query)
$self->{"CGI::Application::Plugin::Header"} "CGI::Header"->new("query", $self->query)
Truth table66%2/3
A ||= B
A= $self->{"CGI::Application::Plugin::Header"}B= "CGI::Header"->new("query", $self->query)
ABresult
1X1
011
000
34 }
35  
36 46 ▶sub header_add {
Subroutine header_add: called CC=8 SCAR=20.8
Pod documented
37 46 my $self = shift;
38 46 ▶ my @props = ref $_[0] eq 'HASH' ? %{$_[0]} : @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 1 45 46
39 46 my $header = $self->header;
40  
41 46 ▶ carp "header_add called while header_type set to 'none'" if $self->header_type eq 'none';
Branch: 1 branch
BranchTrueFalseTotal
if $self->header_type eq "none" 0 46 46
42 46 ▶ croak "Odd number of elements passed to header_add" if @props % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @props % 2 1 45 46
43  
44 45 ▶ while ( my ($key, $value) = splice @props, 0, 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@props, 0, 2)) 46 45 91
45 46 ▶ if ( ref $value eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq "ARRAY") 13 33 46
46 13 ▶ if ( $header->exists($key) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($header->exists($key)) { } 7 6 13
47 7 my $existing_value = $header->get( $key );
48 7 ▶ if ( ref $existing_value eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $existing_value eq 'ARRAY') { } 3 4 7
49 3 $value = [ @$existing_value, @$value ];
50 }
51 else {
52 4 $value = [ $existing_value, @$value ];
53 }
54 }
55 else {
56 6 $value = [ @$value ];
57 }
58 }
59  
60 46 $header->set( $key => $value );
61 }
62  
63 45 return;
64 }
65  
66 57 ▶sub header_props {
Subroutine header_props: called CC=5 SCAR=16.1
Pod documented
67 57 my $self = shift;
68 57 ▶ my @props = ref $_[0] eq 'HASH' ? %{$_[0]} : @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 3 54 57
69 57 my $header = $self->header;
70 57 my $props = $header->header;
71  
72 57 ▶ if ( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 11 46 57
73 11 ▶ carp "header_props called while header_type set to 'none'" if $self->header_type eq 'none';
Branch: 1 branch
BranchTrueFalseTotal
if $self->header_type eq "none" 1 10 11
74 11 ▶ croak "Odd number of elements passed to header_props" if @props % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @props % 2 1 10 11
75 10 $header->clear->set(@props); # replace
76 }
77  
78 56 map { ( "-$_" => $props->{$_} ) } keys %$props; # 'type' -> '-type'
79 }
80  
81 7 1;
82  
83 __END__
↑ Summary