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

filter: Statementstmt 77.4% 24 / 31 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 100% 1 / 1 totaltotal 76.9% 30 / 39 SCAR 11.6
CC
3
Cov
73%
_build_pages
6.8
BEGIN
1.0
BEGIN
1.0
CRAP 3.2
« blib/lib/WebService/LOC/CongRec/Page.pm ↑ Summary blib/lib/WebService/LOC/CongRec/Util.pm »
1 2 ▶use 5.12.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package WebService::LOC::CongRec::Day;
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 Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 =head1 DESCRIPTION
11  
12 An issue of the Congressional Record from a single day on the thomas.loc.gov
13 website. Something along the lines of:
14 http://thomas.loc.gov/cgi-bin/query/B?r111:@FIELD%28FLD003+h%29+@FIELD%28DDATE+20100924%29
15  
16 =cut
17  
18 =head1 ATTRIBUTES
19  
20 =over 1
21  
22 =item mech
23  
24 A WWW::Mechanize object that we can use to grab the page from Thomas.
25  
26 =cut
27  
28 2 has 'mech' => (
29 is => 'rw',
30 isa => 'Object',
31 required => 1,
32 );
33  
34 =item date
35  
36 The date that this page is from.
37  
38 =cut
39  
40 2 has 'date' => (
41 is => 'ro',
42 isa => 'DateTime',
43 required => 1,
44 );
45  
46 =item house
47  
48 Which house of Congress this page is from; (s)enate, (h)ouse, (e)xtension of remarks, (d)aily digest
49  
50 =cut
51  
52 2 has 'house' => (
53 is => 'ro',
54 isa => 'Str',
55 required => 1,
56 );
57  
58 =item pages
59  
60 Pages that are part of this day.
61  
62 =cut
63  
64 2 has 'pages' => (
65 is => 'ro',
66 isa => 'ArrayRef[Str]',
67 auto_deref => 1,
68 lazy_build => 1,
69 builder => '_build_pages',
70 );
71  
72 =back
73  
74 =head1 METHODS
75  
76 =head3 _build_pages
77  
78 Get an array of the pages from this day.
79  
80 Note: these URLs are volatile, expiring 30 minutes after creation.
81  
82 =cut
83  
84 sub _build_pages {
85 2 ▶ my ($self) = @_;
Subroutine _build_pages: called CC=3 SCAR=19.2
86 2 my @pages;
87  
88 2 $self->mech->get($self->getURL);
89  
90 # Line looks like:
91 # <B> 7 . </B> [desc] -- <a href="[url]">(Hou...)</a>
92 # URL: /cgi-bin/query/D?r[congress]:[num]:./temp/~r[congress][random]::
93 0 my $congress = WebService::LOC::CongRec::Util->getCongressFromYear($self->date->year);
94 0 my $lineRegex = qr!<B>\ ?\d{1,3}\ \.\ </B>
95 \ .+\ --\
96 <a\ href="
97 (/cgi-bin/query/D\?r$congress:\d{1,3}:./temp/~r$congress.+::)
98 ">\([HSD]
99 !x;
100  
101 0 my @lines = split /\n/, $self->mech->content;
102 0 foreach my $line (@lines) {
103 0 ▶ if ($line =~ $lineRegex) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /$lineRegex/u) 0 0 0
104 0 push @pages, $1;
105 }
106 }
107  
108 0 return \@pages;
109 }
110  
111 =head3 getURL()
112  
113 Get the Thomas URL for this day.
114  
115 =cut
116  
117 sub getURL {
118 5 ▶ my ($self) = @_;
Subroutine getURL: called CC=1 SCAR=0.0
Pod documented
119  
120 # URL looks like
121 # http://thomas.loc.gov/cgi-bin/query/B?r111:@FIELD(FLD003+s)+@FIELD(DDATE+20100924)
122 5 my $url = 'http://thomas.loc.gov/cgi-bin/query/B?';
123  
124 5 $url .= 'r' . WebService::LOC::CongRec::Util->getCongressFromYear($self->date->year);
125 5 $url .= ':@FIELD(FLD003+' . $self->house . ')';
126 5 $url .= '+@FIELD(DDATE+' . $self->date->strftime('%Y%m%d') . ')';
127  
128 5 return $url;
129 }
130  
131 2 1;
« blib/lib/WebService/LOC/CongRec/Page.pm ↑ Summary blib/lib/WebService/LOC/CongRec/Util.pm »