Prog/Headers.pm

filter: Statementstmt 55.7% 29 / 52 Branchbran 7.1% 1 / 14 Conditioncond 9.0% 1 / 11 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 88.8% 8 / 9 Podpod 100% 2 / 2 totaltotal 44.0% 41 / 93 CC 15 SCAR 44.6
CC
15
Cov
40%
head
151.0
init
3.3
BEGIN
1.0
CRAP 86.1
« Prog/Aggregator.pm ↑ Summary Prog/Config.pm »
1 package SWISH::Prog::Headers;
2  
3 9 ▶use 5.008_003;
Subroutine BEGIN: called CC=1 SCAR=0.0
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 9 ▶use base qw( SWISH::Prog::Class );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 9 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 9 __PACKAGE__->mk_accessors(qw( version ));
9 9 ▶use bytes; # so length() measures bytes
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 9 our $VERSION = '0.75';
12 9 our $AutoURL = time();
13 9 our %Headers = (
14 2 => {
15 url => 'Path-Name',
16 modtime => 'Last-Mtime',
17 parser => 'Document-Type',
18 action => 'Update-Mode',
19 },
20 3 => {
21 url => 'Content-Location',
22 modtime => 'Last-Modified', # but in epoch seconds
23 parser => 'Parser-Type',
24 type => 'Content-Type',
25 action => 'Action',
26 mime => 'Content-Type',
27 }
28  
29 );
30  
31 9 ▶sub init {
Subroutine init: called CC=3 SCAR=12.0
Pod documented
32 9 my $self = shift;
33 9 $self->SUPER::init(@_);
34 9 ▶ $self->{version} ||= 2;
Condition50%1/2
$self->{"version"} ||= 2
l!l
09
MC/DC0%0/1
$self->{"version"} ||= 2
$self->{"version"}
Truth table50%1/2
A
A= $self->{"version"}
Aresult
11
00
35 9 ▶ if ($ENV{SWISH3}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"SWISH3"}) 0 9 9
36 0 $self->{version} = 3;
37 }
38 }
39  
40 0 ▶sub head {
Subroutine head: not called CC=13 SCAR=50.2
Pod documented
41 0 my $self = shift;
42 0 my $buf = shift;
43 0 ▶ $buf = '' unless defined $buf;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $buf 0 0 0
44 0 ▶ my $opts = shift || {};
Condition0%0/2
shift() || {}
l!l
00
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
45  
46 0 ▶ my $version = delete( $opts->{version} ) || $self->version || '2';
Condition0%0/5
delete $opts->{'version'} || $self->version || '2'
l!l
00
delete $opts->{"version"} or $self->version
l!l&&r!l&&!r
000
MC/DC0%0/2
delete $opts->{'version'} || $self->version || '2'
delete $opts->{"version"} $self->version
Truth table0%0/3
A or B
A= delete $opts->{"version"}B= $self->version
ABresult
1X1
011
000
47  
48 0 ▶ $opts->{url} = $AutoURL++ unless exists $opts->{url};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts->{"url"} 0 0 0
49 0 ▶ $opts->{modtime} ||= time();
Condition0%0/2
$opts->{"modtime"} ||= time
l!l
00
MC/DC0%0/1
$opts->{"modtime"} ||= time
$opts->{"modtime"}
Truth table0%0/2
A
A= $opts->{"modtime"}
Aresult
11
00
50  
51 0 my $size = length($buf); #length in bytes, not chars
52  
53 0 ▶ if ( $self->debug > 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->debug > 2) 0 0 0
54 0 warn "length = $size\n";
55 {
56 0 ▶ no bytes;
Subroutine BEGIN: called CC=1 SCAR=0.2
57 0 warn "num chars = " . length($buf) . "\n";
58 0 ▶ if ( $self->debug > 20 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->debug > 20) 0 0 0
59 0 my $c = 0;
60 0 for ( split( //, $buf ) ) {
61 0 warn ++$c . " $_ = " . ord($_) . "\n";
62 }
63 }
64 }
65 }
66  
67 0 my @h = ("Content-Length: $size");
68  
69 0 for my $k ( sort keys %$opts ) {
70 0 ▶ next unless defined $opts->{$k};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts->{$k} 0 0 0
71 0 ▶ my $label = $Headers{$version}->{$k} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $label = $SWISH::Prog::Headers::Headers{$version}{$k} or next 0 0 0
72  
73 # TODO map action to version 2 values
74  
75 0 push( @h, "$label: $opts->{$k}" );
76 }
77  
78 0 return join( "\n", @h ) . "\n\n"; # extra \n required
79 }
80  
81 9 1;
82 __END__
« Prog/Aggregator.pm ↑ Summary Prog/Config.pm »