| 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
| |||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 28 | ▶ | while ( my ($key, $value) = splice @args, 0, 2 ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 24 | 13 | ▶ | $self->{+__PACKAGE__} = $value if lc $key eq 'header'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 33 | 113 | ▶ | $self->{+__PACKAGE__} ||= CGI::Header->new( query => $self->query ); | ||||||||||||||||||
|
Condition66%2/3
$self->{"CGI::Application::Plugin::Header"} ||= "CGI::Header"->new("query", $self->query)
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)
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 42 | 46 | ▶ | croak "Odd number of elements passed to header_add" if @props % 2; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 45 | ▶ | while ( my ($key, $value) = splice @props, 0, 2 ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 45 | 46 | ▶ | if ( ref $value eq 'ARRAY' ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 46 | 13 | ▶ | if ( $header->exists($key) ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 47 | 7 | my $existing_value = $header->get( $key ); | |||||||||||||||||||
| 48 | 7 | ▶ | if ( ref $existing_value eq 'ARRAY' ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 69 | 57 | my $header = $self->header; | |||||||||||||||||||
| 70 | 57 | my $props = $header->header; | |||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | 57 | ▶ | if ( @_ ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 73 | 11 | ▶ | carp "header_props called while header_type set to 'none'" if $self->header_type eq 'none'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 74 | 11 | ▶ | croak "Odd number of elements passed to header_props" if @props % 2; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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__ | ||||||||||||||||||||