blib/lib/WebService/LOC/CongRec/Page.pm

filter: Statementstmt 100% 36 / 36 Branchbran 87.5% 7 / 8 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 1 totaltotal 96.3% 53 / 55 SCAR 19.5
CC
7
Cov
98%
BUILD
7.0
BEGIN
1.0
BEGIN
1.0
CRAP 7.0
« Build ↑ Summary blib/lib/WebService/LOC/CongRec/Day.pm »
1 2 ▶use 5.12.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package WebService::LOC::CongRec::Page;
4 2 our $VERSION = '0.1_04';
5 2 ▶use Moose 1.13;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 with 'MooseX::Log::Log4perl';
7  
8 2 ▶use HTML::Strip;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 =head1 DESCRIPTION
12  
13 A single page from the Congressional Record on THOMAS.
14  
15 The URL is not persistent, but is along the lines of:
16 http://thomas.loc.gov/cgi-bin/query/D?r111:15:./temp/~r111h782Bg::
17  
18 =cut
19  
20 =head1 ATTRIBUTES
21  
22 =over 1
23  
24 =item mech
25  
26 A WWW::Mechanize object that we can use to grab the page from Thomas.
27  
28 =cut
29  
30 2 has 'mech' => (
31 is => 'rw',
32 isa => 'Object',
33 required => 1,
34 );
35  
36 =item url
37  
38 The page URL.
39  
40 =cut
41  
42 2 has 'url' => (
43 is => 'ro',
44 isa => 'Str',
45 required => 1,
46 );
47  
48 =item pageID
49  
50 This page's ID.
51  
52 =cut
53  
54 2 has 'pageID' => (
55 is => 'rw',
56 isa => 'Str',
57 );
58  
59 =item summary
60  
61 This page's summary.
62  
63 =cut
64  
65 2 has 'summary' => (
66 is => 'rw',
67 isa => 'Str',
68 );
69  
70 =item content
71  
72 This page's content.
73  
74 =cut
75  
76 2 has 'content' => (
77 is => 'rw',
78 isa => 'Str',
79 default => '',
80 );
81  
82 =back
83  
84 =cut
85  
86 sub BUILD {
87 3 ▶ my ($self) = @_;
Subroutine BUILD: called CC=7 SCAR=19.5
Pod undocumented
88  
89 3 my $tagStripper = HTML::Strip->new();
90 3 $self->mech->get($self->url);
91  
92 3 my @lines = split /\n/, $self->mech->content;
93 3 foreach my $line (@lines) {
94 # Summary line doesn't have a <p> leader
95 237 ▶ if ($line =~ m!^<b>(.+)</b><br/>!) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ m[^<b>(.+)</b><br/>]u) 3 234 237
96 3 $self->summary($1);
97 3 next;
98 }
99  
100 234 ▶ next if ($line !~ /^<p>/ || $line =~ /^<p>---/);
Branch: 1 branch
BranchTrueFalseTotal
if not $line =~ /^<p>/u or $line =~ /^<p>---/u 222 12 234
Condition100%3/3
not $line =~ /^<p>/u or $line =~ /^<p>---/u
l!l&&r!l&&!r
219312
MC/DC100%2/2
not $line =~ /^<p>/u or $line =~ /^<p>---/u
not $line =~ /^<p>/u $line =~ /^<p>---/u
Truth table100%3/3
not(A) or B
A= not $line =~ /^<p>/uB= $line =~ /^<p>---/u
ABresult
1X1
011
000
101  
102 # Page ID
103 12 ▶ if ($line =~ m!^<p><center><pre>\[Page: ([HSE]\d{1,6})\] <b>!) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^<p><center><pre>\[Page: ([HSE]\d{1,6})\] <b>/u) 3 9 12
104 3 $self->pageID($1);
105 3 next;
106 }
107  
108 # Line of actual content
109 9 ▶ if ($line =~ m/^<p>(.*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^<p>(.*)$/u) 9 0 9
110 9 my $text = $tagStripper->parse($1) . "\n";
111  
112 # Strip non-breaking spaces
113 9 $text =~ s/\xA0//g;
114  
115 9 $self->content($self->content . $text);
116  
117 9 $tagStripper->eof();
118 }
119 }
120 }
121  
122 2 1;
« Build ↑ Summary blib/lib/WebService/LOC/CongRec/Day.pm »