| 1 | package Finance::Bank::Halifax::Sharedealing; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use HTML::TokeParser; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use WWW::Mechanize; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | Finance::Bank::Halifax::Sharedealing - access Halifax Sharedealing accounts from Perl. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | Version 0.03 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 2 | our $VERSION = '0.03'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | use Finance::Bank::Halifax::Sharedealing; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | # Set up the login details | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | my $sd = Finance::Bank::Halifax::Sharedealing->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | username => 'myusername', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | password => 'mysecretpassword', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | security_mother_first_name => 'Alice', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | security_father_first_name => 'Bob', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | security_school_name => 'Somewheretown Primary School', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | security_birthplace => 'Somewheretown', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | $sd->log_in(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | # Get the user's accounts and print a brief statement for each one. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | my %accounts = $sd->get_all_accounts(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | foreach my $account_id (keys(%accounts)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | $sd->set_account($account_id); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | print "Account: " . $accounts{$account_id} . "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | print "Available to invest: " . $sd->get_available_cash() . "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | my @portfolio = $sd->get_portfolio(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | if (@portfolio) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | print "Share\tValuation\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | foreach my $share (@portfolio) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | print $share->{'symbol'} . "\t"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | print $share->{'valuation'} . "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | print "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | $sd->log_out(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | This module provides an interface to the Halifax online share dealing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | service at L<https://www.halifaxsharedealing-online.co.uk/>. It requires | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | C<WWW::Mechanize>, C<HTML::TokeParser>, and either C<Crypt::SSLeay> or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | C<IO::Socket::SSL>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | # Global constants - these will only change if Halifax reorganise their | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | # share dealing site. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | # URL of the login page | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 2 | ▶ | use constant LOGIN_PAGE => 'https://www.halifaxsharedealing-online.co.uk/_mem_bin/formslogin.asp'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | # Text of the link to view your statements | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 2 | ▶ | use constant STATEMENTS_LINK_TEXT => 'My Statements'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | # Name of the account select box on the statements page. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 2 | ▶ | use constant ACCOUNT_SELECT_BOX_NAME => 'AccNavList'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | # Name of the form that contains the 'Sign out' button. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 2 | ▶ | use constant HEADER_FORM_NAME => 'frmHeaderButtons'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | ################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | # Public methods # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | ################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | =head2 new(username => $u, password => $p, security_mother_first_name => $m, security_father_first_name => $f, security_school_name => $s, security_birthplace => $b) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | Returns a new Sharedealing object. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | The required arguments are the user's login details as a list of key/value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | pairs. Answers are required for all the possible security questions, as we | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | don't know in advance which one the site will ask us. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | my ($class, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | croak 'Username not specified' if not exists $opts{username}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | croak 'Password not specified' if not exists $opts{password}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | croak "Security answer not specified: mother's first name" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | if not exists $opts{security_mother_first_name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | croak "Security answer not specified: father's first name" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | if not exists $opts{security_father_first_name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | croak 'Security answer not specified: name of first school' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | if not exists $opts{security_school_name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | croak 'Security answer not specified: place/town of birth' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | if not exists $opts{security_birthplace}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | my $self = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | agent => new WWW::Mechanize(autocheck => 1), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | username => $opts{username}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | password => $opts{password}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | security_mother_first_name => $opts{security_mother_first_name}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | security_father_first_name => $opts{security_father_first_name}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | security_school_name => $opts{security_school_name}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | security_birthplace => $opts{security_birthplace}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | _account => '', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | =head2 log_in() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | Log in, using the security details that were passed to C<new()>. This will | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | set the currently-selected account to the user's default account. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | Returns true if logging in was successful. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | sub log_in { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
log_in: not called CC=7 SCAR=37.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | # ID attribute of the login form | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 2 | ▶ | use constant LOGIN_FORM_ID => 'frmFormsLogin'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | $self->{agent}->get(LOGIN_PAGE); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | $self->{agent}->form_id(LOGIN_FORM_ID); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | $self->{agent}->field('Username', $self->{username}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | $self->{agent}->field('password', $self->{password}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | # Find out what the security question is and select the appropriate answer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | my $stream = HTML::TokeParser->new(\$self->{agent}->{content}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | my $answer = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | while (my $tag = $stream->get_tag('strong')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | my $text = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | $text = $stream->get_trimmed_text('/strong'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | ▶ | if ($text =~ /town of birth/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | $answer = $self->{security_birthplace}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | } elsif ($text =~ /Your father's first name/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | $answer = $self->{security_father_first_name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | } elsif ($text =~ /Your mother's first name/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | $answer = $self->{security_mother_first_name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | } elsif ($text =~ /The name of your first school/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | $answer = $self->{security_school_name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | ▶ | die 'Security question field not found' if !$answer; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | $self->{agent}->field('answer', $answer); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | # Now we've got the answer, submit the page. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | $self->{agent}->submit(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | # Set the currently-selected account to the default. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | $self->{_account} = $self->_get_account_from_url($self->{agent}->uri); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | =head2 log_out() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | Log out by clicking the 'Sign Out' button. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | Returns true if logging out was successful. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | sub log_out { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
log_out: not called CC=1 SCAR=1.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | # The 'Sign off' URL, where the sign off/out button sends you. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 2 | ▶ | use constant SIGN_OFF_URL => 'https://www.halifaxsharedealing-online.co.uk/_mem_bin/SignOff.asp'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | my $form = $self->{agent}->get(SIGN_OFF_URL); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | =head2 get_all_accounts() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | Get all the accounts that can be managed from this user's login. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | Returns a hash with account IDs (e.g. "D12345678") as the keys, and account | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | names (e.g. "MR J SMITH, Halifax ShareBuilder 01") as the values. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | sub get_all_accounts { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_all_accounts: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | my %accounts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | # Go to the statements page, which has a select box with all the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | # accounts in it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | $self->{agent}->follow_link(text => STATEMENTS_LINK_TEXT); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | # Find the select box and extract the account details. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | my $stream = HTML::TokeParser->new(\$self->{agent}->{content}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | ▶ | while (my $token = $stream->get_token) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | my $ttype = shift @{ $token }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | # Is this a start tag? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | ▶ | if($ttype eq 'S') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | my ($tag, $attr, $attrseq, $rawtxt) = @{ $token }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | # Is it the account selection box? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | ▶ | if($tag eq 'select' && $attr->{name} eq ACCOUNT_SELECT_BOX_NAME) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$tag eq "select" and $attr->{"name"} eq "AccNavList"
MC/DC0%0/2
$tag eq "select" and $attr->{"name"} eq "AccNavList"
$tag eq "select"
$attr->{"name"} eq "AccNavList"
Truth table0%0/3
A and B
A= $tag eq "select"B= $attr->{"name"} eq "AccNavList"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | # Found the select box. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | # Now go through each option until we reach the ending select tag. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | ▶ | until ($ttype eq 'E' && $tag eq 'select') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$ttype eq "E" and $tag eq "select"
MC/DC0%0/2
$ttype eq "E" and $tag eq "select"
$ttype eq "E"
$tag eq "select"
Truth table0%0/3
A and B
A= $ttype eq "E"B= $tag eq "select"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | $token = $stream->get_token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | ($ttype, $tag, $attr, $attrseq, $rawtxt) = @{ $token }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | # if we find an opening 'option' tag AND it has a non-blank value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | # (so we skip the 'Show me a different account' option). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | ▶ | if($ttype eq 'S' && $tag eq 'option' && $attr->{value}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$ttype eq "S" and $tag eq "option" and $attr->{"value"}
$ttype eq "S" and $tag eq "option"
MC/DC0%0/3
$ttype eq "S" and $tag eq "option" and $attr->{"value"}
$ttype eq "S"
$tag eq "option"
$attr->{"value"}
Truth table0%0/4
A and B and C
A= $ttype eq "S"B= $tag eq "option"C= $attr->{"value"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | # parse for account ID and account name, then add them to %accounts | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | my $account_code = $self->_get_account_from_url($attr->{value}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | my $account_name = $stream->get_trimmed_text('/option'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | $accounts{$account_code} = $account_name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | return %accounts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | =head2 set_account($account) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | Set or change the account we're using. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | C<$account>: the account ID of the account to switch to. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | Returns true if the account was successfully set, otherwise false. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | ▶ | sub set_account { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_account: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | my ($self, $account) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | my $base_url = $self->_get_url_without_account_code($self->{agent}->uri); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | ▶ | if ($base_url) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | $self->{agent}->get($base_url . $account); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | $self->{_account} = $account; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | warn "Couldn't set the account ID to $account\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | =head2 get_account() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | Get the ID of the account we're currently using. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | Returns the account ID of the currently-selected account (or an empty string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | if there isn't a selected account yet). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | ▶ | sub get_account { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_account: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | return $self->{_account}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | =head2 get_portfolio() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | Get a portfolio statement for the currently-selected account. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | Returns an array. Each element of the array is a hash with the keys: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | symbol: the ticker symbol of the stock. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | exchange: the exchange on which the stock is listed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | quantity: the number of shares owned. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | avg_cost: the average cost per share (in pence). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | latest_price: the latest quoted price per share (in pence). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | change: result of subtracting avg_cost from latest_price (in pence) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | book_cost: total cost of the holding (in pounds) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | valuation: value of the holding at the latest market price (in pounds). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | profit_loss_absolute: the profit or loss on the holding in pounds. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | profit_loss_percent: the profit or loss on the holding in percent. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | All hash values are the raw contents of the data cell - you should not assume | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | that any of them will be valid numbers. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | ▶ | sub get_portfolio { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_portfolio: not called CC=20 SCAR=60.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | $self->{agent}->follow_link(text => STATEMENTS_LINK_TEXT); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | my @portfolio; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | my $stream = HTML::TokeParser->new(\$self->{agent}->{content}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | # Find the portfolio table | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | my $table; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | my ($ttype, $tag, $attr, $attr_seq, $text); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | $table = $stream->get_tag('table'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | ▶ | ($tag, $attr, $attr_seq, $text) = @{ $table } if $table; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | ▶ | } until (!$table || ($attr->{class} && $attr->{class} eq 'DataTable')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
not $table or $attr->{"class"} and $attr->{"class"} eq "DataTable"
$attr->{"class"} and $attr->{"class"} eq "DataTable"
MC/DC0%0/3
not $table or $attr->{"class"} and $attr->{"class"} eq "DataTable"
not $table
$attr->{"class"}
$attr->{"class"} eq "DataTable"
Truth table0%0/4
not(A) or B and C
A= not $tableB= $attr->{"class"}C= $attr->{"class"} eq "DataTable"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | # Couldn't find the table, so just return. Don't give an error, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | # because we might just be looking at an account with no holdings. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | ▶ | if (!$table) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | return @portfolio; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | # Until we get to the end of the table: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | ▶ | do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
not $tag or $ttype eq "E" and $tag eq "table"
$ttype eq "E" and $tag eq "table"
MC/DC0%0/3
not $tag or $ttype eq "E" and $tag eq "table"
not $tag
$ttype eq "E"
$tag eq "table"
Truth table0%0/4
not(A) or B and C
A= not $tagB= $ttype eq "E"C= $tag eq "table"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | my $token = $stream->get_token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | ($ttype, $tag, $attr, $attr_seq, $text) = @{ $token }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | # Process each row we find | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | ▶ | if ($ttype eq 'S' && $tag eq 'tr') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$ttype eq "S" and $tag eq "tr"
MC/DC0%0/2
$ttype eq "S" and $tag eq "tr"
$ttype eq "S"
$tag eq "tr"
Truth table0%0/3
A and B
A= $ttype eq "S"B= $tag eq "tr"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | my @row_contents; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | # Until we get to the end of the row: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | ▶ | do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
not $tag or $ttype eq "E" and $tag eq "table" || $tag eq "tr"
$ttype eq "E" and $tag eq "table" || $tag eq "tr"
$tag eq "table" or $tag eq "tr"
MC/DC0%0/4
not $tag or $ttype eq "E" and $tag eq "table" || $tag eq "tr"
not $tag
$ttype eq "E"
$tag eq "table"
$tag eq "tr"
Truth table0%0/5
not(A) or B and C or D
A= not $tagB= $ttype eq "E"C= $tag eq "table"D= $tag eq "tr"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | $token = $stream->get_token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | ($ttype, $tag, $attr, $attr_seq, $text) = @{ $token }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | # Get the contents of each cell, but ignore header cells. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | ▶ | if ($ttype eq 'S' && $tag eq 'td' && $attr->{class} && $attr->{class} ne 'DataTableCollHeader') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
$ttype eq "S" and $tag eq "td" and $attr->{"class"} and $attr->{"class"} ne "DataTableCollHeader"
$ttype eq "S" and $tag eq "td" and $attr->{"class"}
$ttype eq "S" and $tag eq "td"
MC/DC0%0/4
$ttype eq "S" and $tag eq "td" and $attr->{"class"} and $attr->{"class"} ne "DataTableCollHeader"
$ttype eq "S"
$tag eq "td"
$attr->{"class"}
$attr->{"class"} ne "DataTableCollHeader"
Truth table0%0/5
A and B and C and D
A= $ttype eq "S"B= $tag eq "td"C= $attr->{"class"}D= $attr->{"class"} ne "DataTableCollHeader"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | my $cell_contents = $stream->get_trimmed_text('/td'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | push(@row_contents, $cell_contents); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | } until (!$tag || ($ttype eq 'E' && ($tag eq 'table' || $tag eq 'tr'))); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | # Add the contents of the row we've just processed to the output array. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | ▶ | if (@row_contents >= 10) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | my $new_row = { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 'symbol' => $row_contents[0], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 'exchange' => $row_contents[1], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 'quantity' => $row_contents[2], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 'avg_cost' => $row_contents[3], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 'latest_price' => $row_contents[4], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 'change' => $row_contents[5], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 'book_cost' => $row_contents[6], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 'valuation' => $row_contents[7], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 'profit_loss_absolute' => $row_contents[8], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 'profit_loss_percent' => $row_contents[9], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | push(@portfolio, $new_row); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | } until (!$tag || ($ttype eq 'E' && $tag eq 'table')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | return @portfolio; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | =head2 get_available_cash() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | Get the uninvested cash balance for the currently-selected account. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | Returns the uninvested cash balance as a (ISO-8859-1) string, with currency | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | symbol. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | ▶ | sub get_available_cash { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_available_cash: not called CC=11 SCAR=48.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | my $cash; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | $self->{agent}->follow_link(text => STATEMENTS_LINK_TEXT); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | my $stream = HTML::TokeParser->new(\$self->{agent}->{content}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | ▶ | while (my $td = $stream->get_tag('td')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | my ($tag, $attr, $attr_seq, $text) = @{ $td }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | # Look in the account summary area. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | ▶ | if($attr->{class} && $attr->{class} eq 'summaryBoxesText') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$attr->{"class"} and $attr->{"class"} eq "summaryBoxesText"
MC/DC0%0/2
$attr->{"class"} and $attr->{"class"} eq "summaryBoxesText"
$attr->{"class"}
$attr->{"class"} eq "summaryBoxesText"
Truth table0%0/3
A and B
A= $attr->{"class"}B= $attr->{"class"} eq "summaryBoxesText"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | # Are we at the "Available to invest" line? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | my $text = $stream->get_trimmed_text('/td'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | ▶ | if ($text && ($text =~ /Available to invest/ || $text =~ /Cash in account/)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$text and $text =~ /Available to invest/ || $text =~ /Cash in account/
$text =~ /Available to invest/ or $text =~ /Cash in account/
MC/DC0%0/3
$text and $text =~ /Available to invest/ || $text =~ /Cash in account/
$text
$text =~ /Available to invest/
$text =~ /Cash in account/
Truth table0%0/4
A and B or C
A= $textB= $text =~ /Available to invest/C= $text =~ /Cash in account/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | # If so, get what's in the next <td class="summaryBoxesValues"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | my $cash_td; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | my ($c_tag, $c_attr, $c_attr_seq, $c_text); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | $cash_td = $stream->get_tag('td'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | ▶ | if ($cash_td) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | ($c_tag, $c_attr, $c_attr_seq, $c_text) = @{ $cash_td }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | ▶ | } until (!$cash_td || $c_attr->{class} eq 'summaryBoxesValues'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $cash_td or $c_attr->{"class"} eq "summaryBoxesValues"
MC/DC0%0/2
not $cash_td or $c_attr->{"class"} eq "summaryBoxesValues"
not $cash_td
$c_attr->{"class"} eq "summaryBoxesValues"
Truth table0%0/3
not(A) or B
A= not $cash_tdB= $c_attr->{"class"} eq "summaryBoxesValues"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | ▶ | $cash = $stream->get_trimmed_text('/td') if $cash_td; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | return $cash; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | ################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | # Private methods # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | ################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | # _get_url_without_account_code() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | # Given a URL from the share dealing site (after logging in), return it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | # without the account code on the end. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | # Arguments: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | # $url: the URL from which to remove the account code. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | # Returns the URL without the account code, or false if the account code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | # was not found. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | ▶ | sub _get_url_without_account_code { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_url_without_account_code: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 0 | my ($self, $url) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | my $base = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | $url =~ /^(.*PortCode=)\w+/i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | $base = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | return $base; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | # _get_account_from_url() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | # Given a URL from the share dealing site (after logging in), return the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | # account code from it. Returns an empty string if no account code could | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | # be found. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | # Arguments: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | # $url: the URL from which to extract the account code. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | # Returns the account code, or false if the account code was not found in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | # the URL. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | ▶ | sub _get_account_from_url { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_account_from_url: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | my ($self, $url) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | my $account = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | $url =~ /PortCode=(\w+)/i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 0 | $account = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 0 | return $account; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | =head1 WARNING | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | Taken from Simon Cozens' C<Finance::Bank::LloydsTSB>, because it's just | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | as relevant here: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | This is code for B<online banking>, and that means B<your money>, and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | that means B<BE CAREFUL>. You are encouraged, nay, expected, to audit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | the source of this module yourself to reassure yourself that I am not | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | doing anything untoward with your banking data. This software is useful | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | to me, but is provided under B<NO GUARANTEE>, explicit or implied. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | Rayner Lucas, C<< <cpan at magic-cookie.co.uk> >> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | =head1 BUGS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | Please report any bugs or feature requests to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | C<bug-finance-bank-halifax-sharedealing at rt.cpan.org>, or through the web | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | interface at | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Finance-Bank-Halifax-Sharedealing>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | I will be notified, and then you'll automatically be notified of progress | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | on your bug as I make changes. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | =head1 SUPPORT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | You can find documentation for this module with the perldoc command. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | perldoc Finance::Bank::Halifax::Sharedealing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | You can also look for information at: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | =item * RT: CPAN's request tracker | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Finance-Bank-Halifax-Sharedealing> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | L<http://annocpan.org/dist/Finance-Bank-Halifax-Sharedealing> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | =item * CPAN Ratings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | L<http://cpanratings.perl.org/d/Finance-Bank-Halifax-Sharedealing> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | =item * Search CPAN | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | L<http://search.cpan.org/dist/Finance-Bank-Halifax-Sharedealing/> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | =head1 ACKNOWLEDGEMENTS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | Thanks to the CPAN authors whose modules made this one possible, and to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | Simon Cozens for C<Finance::Bank::LloydsTSB>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | Copyright 2011 Rayner Lucas. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | under the terms of either: the GNU General Public License as published | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | by the Free Software Foundation; or the Artistic License. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | See http://dev.perl.org/licenses/ for more information. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 2 | 1; # End of Finance::Bank::Halifax::Sharedealing | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||