Finance-Bank-LloydsTSB
view release on metacpan or search on metacpan
lib/Finance/Bank/LloydsTSB/Account.pm view on Meta::CPAN
package Finance::Bank::LloydsTSB::Account;
=head1 NAME
Finance::Bank::LloydsTSB::Account -
=head1 SYNOPSIS
synopsis
=head1 DESCRIPTION
description
=cut
use strict;
use warnings;
our $VERSION = '1.35';
our $DEBUG = 0;
use Time::Local;
use Finance::Bank::LloydsTSB::Statement;
use Finance::Bank::LloydsTSB::utils qw(debug);
sub ua { shift->{ua} }
sub name { shift->{name} }
sub descr_num { shift->{descr_num} }
sub sort_code { shift->{sort_code} }
sub account_no { shift->{account_no} }
sub balance { shift->{balance} }
sub parent { shift->{parent} }
sub form_index { shift->{form_index} }
sub _on_account_overview_page {
my $self = shift;
$self->debug("On account overview page?\n");
# Notice case difference of 'O' between this and navigation link to
# this page
if ($self->ua->content =~ /Account Overview/) {
$self->debug("yes\n");
return 1;
}
else {
$self->debug("no\n");
return 0;
}
}
sub _navigate_to_account_overview {
my $self = shift;
if (! $self->_on_account_overview_page) {
# This is the one we want
# my @links = $self->ua->find_all_links;
# my $correct = $links[0]->text;
# GRR! gets decoded into \xa0 by HTML::TokeParser
# (which uses HTML::Entities::decode_entities)
unless ($self->ua->follow_link(text_regex =>
qr/Account[ \xa0]overview/))
{
# my $dumpfile = '/tmp/dump.html';
# $self->debug("Writing content to $dumpfile\n");
# $self->ua->save_content($dumpfile);
# my @context = $self->ua->content =~ /(.{100}overview.{100,}?$)/gims;
# die "no overview???", $self->ua->content
# unless @context;
# map "---\n$_\n---\n", @context;
die "Couldn't go to account overview page\n";
}
$self->debug("Gone to account overview page\n");
}
}
sub _on_account_details_page {
my $self = shift;
$self->debug("On details page for ", $self->name, "?\n");
if ($self->ua->content !~ /Your account details/) {
$self->debug("no\n");
return 0;
}
if ($self->_check_selected_account_text) {
$self->debug("yes\n");
return 1;
}
$self->debug("no\n");
return 0;
}
sub _check_selected_account_text {
my $self = shift;
# Look for a table which has the right 'Selected account' in the
# header.
my $te = new HTML::TableExtract;
$te->parse($self->ua->content);
foreach my $ts ($te->table_states) {
my @rows = $ts->rows;
my $header = $rows[0];
foreach my $td (@$header) {
if ($td =~ /Selected account/ && (index($td, $self->{name}) >= 0)) {
return 1;
}
}
}
return 0;
}
sub _navigate_to_details {
my $self = shift;
if ($self->_on_account_details_page) {
$self->debug("Already on details page for ", $self->name, "\n");
return;
( run in 1.715 second using v1.01-cache-2.11-cpan-5e09290becf )