blib/lib/Text/SuDocs.pm

filter: Statementstmt 98.5% 70 / 71 Branchbran 92.8% 26 / 28 Conditioncond 70.5% 12 / 17 MC/DCmcdc 50.0% 5 / 10 Subroutinesub 100% 10 / 10 Podpod 75.0% 3 / 4 totaltotal 90.0% 126 / 140 CC 21 SCAR 17.7
CC
21
Cov
93%
parse
10.2
normal_string
7.0
__ANON__
3.0
CRAP 5.9
↑ Summary
1 package Text::SuDocs;
2 {
3 5 $Text::SuDocs::VERSION = '0.014';
4 }
5  
6 # ABSTRACT: parse and normalize SuDocs numbers
7  
8 5 ▶use 5.10.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 5 ▶use Any::Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 5 our @subfields = qw{agency subagency committee series relatedseries document};
15  
16 5 has [qw(original), @subfields] => (
17 is => 'rw',
18 isa => 'Maybe[Str]',
19 );
20  
21 1112 ▶around BUILDARGS => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
22 1112 my $orig = shift;
23 1112 my $class = shift;
24  
25 1112 ▶ if (@_ == 1 && !ref $_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and not ref $_[0]) { } 1105 7 1112
Condition100%3/3
@_ == 1 and not ref $_[0]
!ll&&!rl&&r
161105
MC/DC100%2/2
@_ == 1 and not ref $_[0]
@_ == 1 not ref $_[0]
Truth table100%3/3
A and not(B)
A= @_ == 1B= not ref $_[0]
ABresult
0X0
100
111
26 1105 return $class->$orig(original => $_[0]);
27 }
28 else {
29 7 return $class->$orig(@_);
30 }
31 5 };
32  
33 1112 ▶sub BUILD {
Subroutine BUILD: called CC=2 SCAR=6.9
Pod documented
34 1112 my $self = shift;
35 1112 ▶ if($self->original) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->original) 1105 7 1112
36 1105 $self->parse;
37 }
38 }
39  
40 2219 ▶around 'original' => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
41 2219 my $orig = shift;
42 2219 my $self = shift;
43  
44 2219 ▶ if (scalar @_) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_) 1 2218 2219
45 1 $self->$orig(@_);
46 1 $self->parse();
47 }
48  
49 2219 return $self->$orig();
50 5 };
51  
52 1106 ▶sub parse {
Subroutine parse: called CC=10 SCAR=23.2
Pod undocumented
53 1106 my $self = shift;
54 1106 ▶ my $original = shift // $self->original;
Condition33%1/3
shift() // $self->original
l!l&&r!l&&!r
011060
MC/DC0%0/2
shift() // $self->original
shift() $self->original
Truth table33%1/3
A // B
A= shift()B= $self->original
ABresult
1X1
011
000
55 1106 ▶ return if ! defined $original;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $original 0 1106 1106
56  
57 1106 chomp($original);
58 1106 ▶ croak 'Invalid characters' if $original =~ qr{[^\p{IsAlnum}\s:/\-.<>()]};
Branch: 1 branch
BranchTrueFalseTotal
if $original =~ qr"[^\p{IsAlnum}\s:/\-.<>()]" 2 1104 1106
59 1104 $original = uc $original;
60 1104 $original =~ s{^\s+|\s+$}{}g;
61 1104 $original =~ s{\s+}{ }g;
62 1104 $original =~ s{:$}{};
63  
64 1104 ▶ if ($original =~ /^(XJH|XJS)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($original =~ /^(XJH|XJS)$/) 5 1099 1104
65 5 $self->agency($1);
66 5 return $self;
67 }
68  
69 1099 $original =~ qr{
70 ^(\p{IsAlpha}+)\s* #Agency
71 (\p{IsDigit}+)\s*\.\s* #Subagency
72 (?:(\p{IsAlpha}+)\s+)? #Committee
73 (\p{IsDigit}+) #Series
74 (?:/(\p{IsAlnum}+)(-\p{IsAlnum}+)?)?\s* #RelSeries
75 (?::\s*(.*))?$ #Document
76 }x;
77 1099 ▶ croak 'Unable to determine stem' if (!($1 && $2 && $4));
Branch: 1 branch
BranchTrueFalseTotal
unless $1 and $2 and $4 10 1089 1099
Condition66%4/6
$1 and $2 and $4
!ll&&!rl&&r
1001089
$1 and $2
!ll&&!rl&&r
1001089
MC/DC33%1/3
$1 and $2 and $4
$1 $2 $4
Truth table50%2/4
A and B and C
A= $1B= $2C= $4
ABCresult
0XX0
10X0
1100
1111
78  
79 1089 $self->agency($1);
80 1089 $self->subagency($2);
81 1089 $self->committee($3);
82 1089 $self->series($4);
83 1089 ▶ my $relseries =
Branch: 2 branches
BranchTrueFalseTotal
!$5 ? : 48 1041 1089
$6 ? : 21 1020 1041
84 (!$5) ? undef :
85 ($6) ? $5.$6 : $5;
86 1089 $self->relatedseries($relseries);
87 1089 $self->document($7);
88  
89 1089 return $self;
90 }
91  
92 1137 ▶sub normal_string {
Subroutine normal_string: called CC=7 SCAR=19.5
Pod documented
93 1137 my $self = shift;
94 0 ▶ my %args = (ref $_[0]) ? %{$_[0]} : @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 1137 1137
95  
96 1137 ▶ return $self->agency if ($self->agency =~ /^(?:XJH|XJS)$/);
Branch: 1 branch
BranchTrueFalseTotal
if $self->agency =~ /^(?:XJH|XJS)$/ 15 1122 1137
97  
98 1122 ▶ my $sudocs = sprintf(
Branch: 2 branches
BranchTrueFalseTotal
$self->committee ? : 1045 77 1122
$self->relatedseries ? : 1053 69 1122
99 '%s %d.%s%s%s',
100 $self->agency,
101 $self->subagency,
102 ($self->committee) ? $self->committee . q{ } : '',
103 $self->series,
104 ($self->relatedseries) ? '/'.$self->relatedseries : '',
105 );
106  
107 1122 ▶ unless ($args{class_stem} || !$self->document) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"class_stem"} or not $self->document) 1100 22 1122
Condition100%3/3
$args{"class_stem"} or not $self->document
l!l&&r!l&&!r
1751100
MC/DC100%2/2
$args{"class_stem"} or not $self->document
$args{"class_stem"} not $self->document
Truth table100%3/3
A or not(B)
A= $args{"class_stem"}B= not $self->document
ABresult
1X1
011
000
108 1100 $sudocs .= ':'.$self->document;
109 }
110 1122 return $sudocs;
111 }
112  
113 22 ▶sub sortable_string {
Subroutine sortable_string: called CC=2 SCAR=7.0
Pod documented
114 22 my $self = shift;
115 22 ▶ my $pad = shift // 8;
Condition50%1/2
shift() // 8
l!l
022
MC/DC0%0/1
shift() // 8
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
116  
117 22 my $s = $self->normal_string;
118 22 my $format = sprintf '%%0%dd', $pad;
119 22 $s =~ s/\b(\d+)\b/sprintf $format, $1/xge;
120 22 $s =~ s/\s/_/g;
121  
122 22 return $s;
123 }
124  
125 5 __PACKAGE__->meta()->make_immutable();
126 5 1;
127  
128 __END__
↑ Summary