ActionPack/PriorityList.pm

filter: Statementstmt 100% 54 / 54 Branchbran 75.0% 6 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 16 / 16 Podpod 100% 12 / 12 totaltotal 97.7% 88 / 90 CC 7 SCAR 4.9
CC
7
Cov
97%
add
3.0
priority_of
2.0
BUILD
2.0
CRAP 1.6
« ActionPack/Core/BaseHeaderWithParams.pm ↑ Summary ActionPack/Core/BaseHeaderList.pm »
1 package HTTP::Headers::ActionPack::PriorityList;
2 # ABSTRACT: A Priority List
3  
4 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 6 our $VERSION = '0.10';
8  
9 6 ▶use HTTP::Headers::ActionPack::Util qw[
Subroutine BEGIN: called CC=1 SCAR=0.0
10 split_header_words
11 join_header_words
12 6 ];
13  
14 6 ▶use parent 'HTTP::Headers::ActionPack::Core::BaseHeaderList';
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 66 ▶sub BUILDARGS { +{ 'index' => {}, 'items' => {} } }
Subroutine BUILDARGS: called CC=1 SCAR=0.0
Pod documented
17  
18 38 ▶sub BUILD {
Subroutine BUILD: called CC=2 SCAR=6.9
Pod documented
19 38 my ($self, @items) = @_;
20 38 foreach my $item ( @items ) {
21 5 $self->add( @$item )
22 }
23 }
24  
25 244 ▶sub index { (shift)->{'index'} }
Subroutine index: called CC=1 SCAR=0.0
Pod documented
26 658 ▶sub items { (shift)->{'items'} }
Subroutine items: called CC=1 SCAR=0.0
Pod documented
27  
28 62 ▶sub new_from_string {
Subroutine new_from_string: called CC=2 SCAR=6.9
Pod documented
29 62 my ($class, $header_string) = @_;
30 62 my $list = $class->new;
31 62 foreach my $header ( split_header_words( $header_string ) ) {
32 144 $list->add_header_value( $header );
33 }
34 62 $list;
35 }
36  
37 5 ▶sub as_string {
Subroutine as_string: called CC=1 SCAR=0.0
Pod documented
38 5 my $self = shift;
39 join ', ' => map {
40 5 my ($q, $subject) = @{ $_ };
41 18 join_header_words( $subject, q => $q );
42 } $self->iterable;
43 }
44  
45 162 ▶sub add {
Subroutine add: called CC=3 SCAR=11.0
Pod documented
46 162 my ($self, $q, $choice) = @_;
47 # XXX - should failure to canonicalize be an error? or should
48 # canonicalize_choice itself throw an error on bad values?
49 162 ▶ $choice = $self->canonicalize_choice($choice)
Branch: 1 branch
BranchTrueFalseTotal
$choice = $self->canonicalize_choice($choice) or return 162 0 162
50 or return;
51 162 $q += 0; # be sure to numify this
52 162 $self->index->{ $choice } = $q;
53 162 ▶ $self->items->{ $q } = [] unless exists $self->items->{ $q };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->items->{$q} 121 41 162
54 162 push @{ $self->items->{ $q } } => $choice;
55 }
56  
57 68 ▶sub add_header_value {
Subroutine add_header_value: called CC=2 SCAR=6.9
Pod documented
58 68 my $self = shift;
59 68 my ($choice, %params) = @{ $_[0] };
60 68 ▶ $self->add( exists $params{'q'} ? $params{'q'} : 1.0, $choice );
Branch: 1 branch
BranchTrueFalseTotal
exists $params{'q'} ? : 26 42 68
61 }
62  
63 7 ▶sub get {
Subroutine get: called CC=1 SCAR=0.0
Pod documented
64 7 my ($self, $q) = @_;
65 7 $self->items->{ $q };
66 }
67  
68 82 ▶sub priority_of {
Subroutine priority_of: called CC=2 SCAR=7.1
Pod documented
69 82 my ($self, $choice) = @_;
70 82 ▶ $choice = $self->canonicalize_choice($choice)
Branch: 1 branch
BranchTrueFalseTotal
$choice = $self->canonicalize_choice($choice) or return 82 0 82
71 or return;
72 82 $self->index->{ $choice };
73 }
74  
75 43 ▶sub iterable {
Subroutine iterable: called CC=1 SCAR=0.0
Pod documented
76 43 my $self = shift;
77 map {
78 81 my $q = $_;
79 81 map { [ $q, $_ ] } @{ $self->items->{ $q } }
80 43 } reverse sort keys %{ $self->items };
81 }
82  
83 46 ▶sub canonicalize_choice {
Subroutine canonicalize_choice: called CC=1 SCAR=0.0
Pod documented
84 46 return $_[1];
85 }
86  
87 6 1;
88  
89 __END__
« ActionPack/Core/BaseHeaderWithParams.pm ↑ Summary ActionPack/Core/BaseHeaderList.pm »