| 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 WWW::Mechanize; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||
| 11 | 2 | our $VERSION = '0.06'; | |||||||||||||||||||||||||||||||
| 12 | 2 | our $checker_url = 'http://www.nsandi.com/savings-premium-bonds-have-i-won'; | |||||||||||||||||||||||||||||||
| 13 | 2 | our $agent_string = "Perl/Finance::PremiumBonds $VERSION"; | |||||||||||||||||||||||||||||||
| 14 | 2 | our $holdernumfield = 'pbhn'; | |||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||
| 16 | sub has_won { | ||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||
| 18 | 0 | ▶ | my $holdernum = shift | ||||||||||||||||||||||||||||||
|
Subroutine
has_won: not called CC=9 SCAR=45.0
Pod
documented
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")
| |||||||||||||||||||||||||||||||||
| 19 | or carp "No holder number supplied" and return; | ||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||
| 22 | 0 | my $mech = WWW::Mechanize->new( agent => $agent_string ); | |||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||
| 24 | 0 | $mech->get($checker_url); | |||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | if (!$mech->success) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 27 | 0 | warn "Initial request failed - " . $mech->response->status_line; | |||||||||||||||||||||||||||||||
| 28 | 0 | return; | |||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||
| 32 | 0 | my $form = $mech->form_with_fields($holdernumfield); | |||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | if (!$form) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 34 | 0 | warn "Failed to find form containing $holdernumfield " | |||||||||||||||||||||||||||||||
| 35 | . " - perhaps NS+I website has been changed"; | ||||||||||||||||||||||||||||||||
| 36 | 0 | return; | |||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||
| 39 | 0 | $mech->field($holdernumfield, $holdernum); | |||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | if (!$mech->click('submit')) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 41 | 0 | warn "Unable to submit lookup - " . $mech->response->status_line; | |||||||||||||||||||||||||||||||
| 42 | 0 | return; | |||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | if ($mech->content =~ /holder number must be 10 numbers/msi | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$mech->content =~ /holder number must be 10 numbers/ism or $mech->content =~ /check your holder's number - it is not valid/ism
MC/DC0%0/2
$mech->content =~ /holder number must be 10 numbers/ism or $mech->content =~ /check your holder's number - it is not valid/ism
$mech->content =~ /holder number must be 10 numbers/ism
$mech->content =~ /check your holder's number - it is not valid/ism
Truth table0%0/3
A or B
A= $mech->content =~ /holder number must be 10 numbers/ismB= $mech->content =~ /check your holder's number - it is not valid/ism
| |||||||||||||||||||||||||||||||||
| 45 | || $mech->content =~ /check your holder's number - it is not valid/msi) | ||||||||||||||||||||||||||||||||
| 46 | { | ||||||||||||||||||||||||||||||||
| 47 | 0 | carp "Holder number not recognised by NS+I"; | |||||||||||||||||||||||||||||||
| 48 | 0 | return; | |||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||
| 52 | # TODO: it'd be nice to actually detect a winning response, rather than | ||||||||||||||||||||||||||||||||
| 53 | # the lack of a losing response - but I need a holder's number which has | ||||||||||||||||||||||||||||||||
| 54 | # actually won in order to see what the response is :) | ||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | return ($mech->content =~ m{Sorry,? you haven't won}i) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 56 | ? 0 : 1; | ||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||
| 61 | 2 | 1; | |||||||||||||||||||||||||||||||
| 62 | __END__ | ||||||||||||||||||||||||||||||||