| 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
MC/DC0%0/1
$self->{"version"} ||= 2
$self->{"version"}
Truth table50%1/2
A
A= $self->{"version"}
| |||||||||||||||||||||||||
| 35 | 9 | ▶ | if ($ENV{SWISH3}) { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||
| 44 | 0 | ▶ | my $opts = shift || {}; | ||||||||||||||||||||||
|
Condition0%0/2
shift() || {}
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||
| 46 | 0 | ▶ | my $version = delete( $opts->{version} ) || $self->version || '2'; | ||||||||||||||||||||||
|
Condition0%0/5
delete $opts->{'version'} || $self->version || '2'
delete $opts->{"version"} or $self->version
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
| |||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||
| 48 | 0 | ▶ | $opts->{url} = $AutoURL++ unless exists $opts->{url}; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 49 | 0 | ▶ | $opts->{modtime} ||= time(); | ||||||||||||||||||||||
|
Condition0%0/2
$opts->{"modtime"} ||= time
MC/DC0%0/1
$opts->{"modtime"} ||= time
$opts->{"modtime"}
Truth table0%0/2
A
A= $opts->{"modtime"}
| |||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||
| 51 | 0 | my $size = length($buf); #length in bytes, not chars | |||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||
| 53 | 0 | ▶ | if ( $self->debug > 2 ) { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||
| 71 | 0 | ▶ | my $label = $Headers{$version}->{$k} or next; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||