blib/lib/Finance/PremiumBonds.pm

filter: Statementstmt 64.7% 22 / 34 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 85.7% 6 / 7 Podpod 100% 1 / 1 totaltotal 46.0% 29 / 63 CC 8 SCAR 37.3
CC
8
Cov
43%
has_won
72.0
BEGIN
1.0
BEGIN
1.0
CRAP 41.6
↑ Summary
1 package Finance::PremiumBonds;
2  
3 # $Id$
4  
5 2 ▶use 5.005000;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 our $VERSION = '0.07';
13 2 our $checker_url = 'http://www.nsandi.com/premium-bonds-have-i-won-ajax';
14 2 our $agent_string = "Perl/Finance::PremiumBonds $VERSION";
15 2 our $holdernumfield = '';
16  
17 0 ▶sub has_won {
Subroutine has_won: not called CC=8 SCAR=42.8
Pod documented
18  
19 0 ▶ my $holdernum = shift
Branch: 1 branch
BranchTrueFalseTotal
my $holdernum = shift() or carp("No holder number supplied") and return 0 0 0
Condition0%0/5
(my $holdernum = shift()) || carp('No holder number supplied') && (return)
l!l&&r!l&&!r
000
carp("No holder number supplied") and return
!ll
00
MC/DC0%0/2
(my $holdernum = shift()) || carp('No holder number supplied') && (return)
(my $holdernum = shift()) carp("No holder number supplied")
Truth table0%0/3
A || B
A= (my $holdernum = shift())B= carp("No holder number supplied")
ABresult
1X1
011
000
20 or carp "No holder number supplied" and return;
21  
22 0 ▶ my $period = shift || 'this_month';
Condition0%0/2
shift() || 'this_month'
l!l
00
MC/DC0%0/1
shift() || 'this_month'
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
23  
24 0 my $ua = LWP::UserAgent->new( agent => $agent_string );
25 0 ▶ my $resp = $ua->post(
Condition0%0/2
$period || 'this_month'
l!l
00
MC/DC0%0/1
$period || 'this_month'
$period
Truth table0%0/2
A
A= $period
Aresult
11
00
26 $checker_url,
27 {
28 field_premium_bond_number => $holdernum,
29 field_premium_bond_period => $period || 'this_month',
30 }
31 );
32  
33 0 ▶ if (!$resp->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($resp->is_success) 0 0 0
34 0 warn "Request failed - " . $resp->status_line;
35 0 return;
36 }
37  
38 0 my $resp_data = JSON::from_json($resp->decoded_content);
39  
40 0 ▶ if ($resp_data->{holder_number} eq 'is_invalid') {
Branch: 1 branch
BranchTrueFalseTotal
if ($resp_data->{"holder_number"} eq "is_invalid") 0 0 0
41 0 carp "Holder number not recognised by NS+I";
42 0 return;
43 }
44  
45 # TODO: it'd be nice to know what the status is for a win (just 'win'?) but
46 # I've never won, so I don't know - so for now, just treat the absence of
47 # 'no_win' as a win.
48 0 ▶ return $resp_data->{status} eq 'no_win' ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$resp_data->{'status'} eq 'no_win' ? : 0 0 0
49 }
50  
51  
52  
53 2 1;
54 __END__
↑ Summary