| 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
Condition0%0/5
(my $holdernum = shift()) || carp('No holder number supplied') && (return)
carp("No holder number supplied") and return
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")
| |||||||||||||||||||||||||||||||||
| 20 | or carp "No holder number supplied" and return; | ||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||
| 22 | 0 | ▶ | my $period = shift || 'this_month'; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
shift() || 'this_month'
MC/DC0%0/1
shift() || 'this_month'
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||
| 24 | 0 | my $ua = LWP::UserAgent->new( agent => $agent_string ); | |||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | my $resp = $ua->post( | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$period || 'this_month'
MC/DC0%0/1
$period || 'this_month'
$period
Truth table0%0/2
A
A= $period
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||
| 53 | 2 | 1; | |||||||||||||||||||||||||||||||
| 54 | __END__ | ||||||||||||||||||||||||||||||||