lib/Finance/Bank/Wachovia/DataObtainer/WWW.pm

filter: Statementstmt 60.1% 107 / 178 Branchbran 28.7% 19 / 66 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 86.8% 33 / 38 Podpod 0.0% 0 / 15 totaltotal 50.9% 159 / 312 SCAR 53.5
CC
37
Cov
50%
login
210.0
get_detail_content
25.8
get_summary_content
16.1
CRAP 210.2
↑ Summary lib/Finance/Bank/Wachovia/Account.pm »
1 package Finance::Bank::Wachovia::DataObtainer::WWW;
2  
3 6 ▶use WWW::Mechanize;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use HTTP::Cookies;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use Finance::Bank::Wachovia::DataObtainer::WWW::Parser;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use Finance::Bank::Wachovia::ErrorHandler;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 6 our $VERSION = '0.2';
11 6 ▶my $DEBUG = 1 if "@ARGV" =~ /--www-debug/;
Branch: 1 branch
BranchTrueFalseTotal
if join($", @ARGV) =~ /--www-debug/ 0 6 6
12 6 ▶my $CONFIRM_LOGIN = 1 if "@ARGV" =~ /--www-confirm/;
Branch: 1 branch
BranchTrueFalseTotal
if join($", @ARGV) =~ /--www-confirm/ 0 6 6
13 6 my @attrs;
14 6 our @ISA = qw/Finance::Bank::Wachovia::ErrorHandler/;
15  
16 BEGIN{
17 6 ▶ @attrs = qw(
Subroutine BEGIN: called CC=2 SCAR=7.0
18 customer_access_number
19 user_id
20 password
21 pin
22 code_word
23 cached_content
24 mech
25 start_url
26 logged_in
27 );
28
29 6 my $x = @__SUPER__::ATTRIBUTES;
30 6 for( @attrs ){
31 54 ▶ eval "sub _$_ { $x }";
Subroutine _cached_content: called CC=1 SCAR=0.1
Subroutine _code_word: called CC=1 SCAR=0.1
Subroutine _customer_access_number: called CC=1 SCAR=0.1
Subroutine _logged_in: not called CC=1 SCAR=0.1
Subroutine _mech: not called CC=1 SCAR=0.1
Subroutine _password: called CC=1 SCAR=0.1
Subroutine _pin: called CC=1 SCAR=0.1
Subroutine _start_url: called CC=1 SCAR=0.1
Subroutine _user_id: called CC=1 SCAR=0.1
32 54 $x++;
33 }
34 }
35  
36 sub new {
37 10 ▶ my($class, %attrs) = @_;
Subroutine new: called CC=2 SCAR=6.9
Pod undocumented
38 10 my $self = [];
39 10 bless $self, $class;
40 10 foreach my $att ( keys %attrs ){
41 10 $self->$att( $attrs{$att} );
42 }
43 10 $self->init();
44 10 return $self;
45 }
46  
47 sub init {
48 6 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
49 10 ▶ my $self = shift;
Subroutine init: called CC=2 SCAR=7.0
Pod undocumented
50 10 ▶ $self->start_url('https://onlineservices.wachovia.com/auth/AuthService?action=presentLogin')
Branch: 1 branch
BranchTrueFalseTotal
unless $self->start_url 10 0 10
51 unless $self->start_url;
52 10 $self->[ &{"_cached_content"} ] = {};
53 }
54  
55 sub AUTOLOAD {
56 6 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
57 144 ▶ our $AUTOLOAD;
Subroutine AUTOLOAD: called CC=3 SCAR=11.0
58 144 my $self = shift;
59 144 my $attr = lc $AUTOLOAD;
60 144 $attr =~ s/.*:://;
61 144 ▶ return $self->Error("$attr is not a valid attribute")
Branch: 1 branch
BranchTrueFalseTotal
unless grep /$attr/, @attrs 0 144 144
62 unless grep /$attr/, @attrs;
63 # get if no args passed
64 144 ▶ return $self->[ &{"_$attr"} ] unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 114 30 144
65 # set if args passed
66 30 $self->[ &{"_$attr"} ] = shift;
67 30 return $self;
68 }
69  
70 sub trash_cache {
71 0 ▶ my $self = shift;
Subroutine trash_cache: not called CC=1 SCAR=6.9
Pod undocumented
72 0 $self->[ &{"_cached_content"} ] = {};
73 }
74  
75 sub get_account_numbers {
76 8 ▶ my $self = shift;
Subroutine get_account_numbers: called CC=1 SCAR=0.0
Pod undocumented
77 8 return Finance::Bank::Wachovia::DataObtainer::WWW::Parser
78 ->get_account_numbers( $self->get_summary_content() );
79 }
80  
81 sub get_credit_account_current_balance {
82 1 ▶ get_account_available_balance( @_ );
Subroutine get_credit_account_current_balance: called CC=1 SCAR=0.0
Pod undocumented
83 }
84  
85 sub get_credit_account_available_credit {
86 2 ▶ my $self = shift;
Subroutine get_credit_account_available_credit: called CC=2 SCAR=7.1
Pod undocumented
87 2 ▶ return $self->Error( "must pass credit account number" ) unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 2 2
88 2 return Finance::Bank::Wachovia::DataObtainer::WWW::Parser
89 ->get_credit_account_available_credit( $self->get_detail_content( @_ ) );
90 }
91  
92 sub get_credit_account_limit {
93 2 ▶ my $self = shift;
Subroutine get_credit_account_limit: called CC=2 SCAR=7.1
Pod undocumented
94 2 ▶ return $self->Error( "must pass credit account number" ) unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 2 2
95 2 return Finance::Bank::Wachovia::DataObtainer::WWW::Parser
96 ->get_credit_account_limit( $self->get_detail_content( @_ ) );
97  
98 }
99  
100 sub get_account_available_balance {
101 8 ▶ my $self = shift;
Subroutine get_account_available_balance: called CC=2 SCAR=7.1
Pod undocumented
102 8 ▶ return $self->Error( "must pass account number" ) unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 8 8
103 8 return Finance::Bank::Wachovia::DataObtainer::WWW::Parser
104 ->get_account_available_balance( $self->get_summary_content(), @_ );
105 }
106  
107 sub get_account_name {
108 9 ▶ my $self = shift;
Subroutine get_account_name: called CC=2 SCAR=7.1
Pod undocumented
109 9 ▶ return $self->Error( "must pass account number" ) unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 9 9
110 9 return Finance::Bank::Wachovia::DataObtainer::WWW::Parser
111 ->get_account_name( $self->get_summary_content(), @_ );
112 }
113  
114 sub get_account_type {
115 4 ▶ my($self) = shift;
Subroutine get_account_type: called CC=2 SCAR=7.1
Pod undocumented
116 4 ▶ return $self->Error( "must pass account number" ) unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 4 4
117 4 return Finance::Bank::Wachovia::DataObtainer::WWW::Parser
118 ->get_account_type( $self->get_detail_content(@_) );
119 }
120  
121 sub get_account_posted_balance {
122 1 ▶ my $self = shift;
Subroutine get_account_posted_balance: called CC=2 SCAR=7.1
Pod undocumented
123 1 ▶ return $self->Error( "must pass account number" ) unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 1 1
124 1 return Finance::Bank::Wachovia::DataObtainer::WWW::Parser
125 ->get_account_posted_balance( $self->get_detail_content(@_) );
126 }
127  
128 sub get_account_transactions {
129 3 ▶ my $self = shift;
Subroutine get_account_transactions: called CC=2 SCAR=7.1
Pod undocumented
130 3 ▶ return $self->Error( "must pass account number" ) unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 3 3
131 3 return Finance::Bank::Wachovia::DataObtainer::WWW::Parser
132 ->get_account_transactions( $self->get_detail_content(@_) );
133 }
134  
135 sub get_summary_content {
136 6 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
137 27 ▶ local $^W = 0;
Subroutine get_summary_content: called CC=6 SCAR=27.8
Pod undocumented
138 27 ▶ print STDERR "Getting Summary Content:\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $DEBUG 0 27 27
139 27 my $self = shift;
140 27 ▶ if( $self->cached_content->{'summary'} ){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->cached_content->{"summary"}) 27 0 27
141 print STDERR "Returning cached summary:\n",
142 "============== BEGIN SUMMARY =============\n",
143 27 ▶ $self->cached_content->{'summary'}, "\n",
Branch: 1 branch
BranchTrueFalseTotal
if $DEBUG 0 27 27
144 "=============== END SUMMARY ==============\n" if $DEBUG;
145 27 return $self->cached_content->{'summary'};
146 }
147 0 ▶ if( ! $self->logged_in ){
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->logged_in) 0 0 0
148 0 $self->login;
149 0 return $self->get_summary_content();
150 }
151 0 my $mech = $self->mech();
152 0 $mech->form_number( 1 );
153 0 $mech->field( inputName => 'RelationshipSummary' );
154 0 $mech->submit();
155 0 $self->cached_content->{'summary'} = $mech->content();
156 print STDERR "Returning NOT cached summary:\n",
157 "============== BEGIN SUMMARY =============\n",
158 0 ▶ $self->cached_content->{'summary'}, "\n",
Branch: 1 branch
BranchTrueFalseTotal
if $DEBUG 0 0 0
159 "=============== END SUMMARY ==============\n" if $DEBUG;
160 0 return $self->cached_content->{'summary'};
161 }
162  
163 sub get_detail_content {
164 6 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
165 14 ▶ local $^W = 0;
Subroutine get_detail_content: called CC=7 SCAR=32.5
Pod undocumented
166 14 my($self, $account_number) = @_;
167 14 ▶ return $self->Error( "get_detail_content in WWW must have account_number, got: '$account_number'" )
Branch: 1 branch
BranchTrueFalseTotal
unless $account_number 0 14 14
168 unless $account_number;
169 14 ▶ if( $self->cached_content->{'details'}{$account_number} ){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->cached_content->{"details"}{$account_number}) 14 0 14
170 print STDERR "Returning cached details:\n",
171 "============ BEGIN DETAILS ===============\n",
172 14 ▶ $self->cached_content->{'details'}{$account_number}, "\n",
Branch: 1 branch
BranchTrueFalseTotal
if $DEBUG 0 14 14
173 "============ END DETAILS =================\n" if $DEBUG;
174 14 return $self->cached_content->{'details'}->{$account_number};
175 }
176 0 ▶ unless( $self->cached_content->{'summary'} ){
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->cached_content->{"summary"}) 0 0 0
177 0 $self->get_summary_content();
178 }
179 0 ▶ my $stmt_type = $account_number =~ /^\d{16}$/ ? 'AccountSummary' : 'AccountDetail';
Branch: 1 branch
BranchTrueFalseTotal
$account_number =~ /^\d{16}$/ ? : 0 0 0
180 0 my $mech = $self->mech();
181 0 $mech->form_number( 1 );
182 0 $mech->field( RelSumAcctSel => $account_number );
183 0 $mech->field( inputName => $stmt_type );
184 0 $mech->field( RelSumStmtType => $stmt_type );
185 0 $mech->submit();
186 0 $self->cached_content->{'details'}->{$account_number} = $mech->content();
187 # return to summary page
188 0 $mech->form_number( 1 );
189 0 $mech->field( inputName => 'RelationshipSummary' );
190 0 $mech->submit();
191 print STDERR "Returning NOT cached details:\n",
192 "============ BEGIN DETAILS ===============\n",
193 0 ▶ $self->cached_content->{'details'}{$account_number}, "\n",
Branch: 1 branch
BranchTrueFalseTotal
if $DEBUG 0 0 0
194 "============ END DETAILS =================\n" if $DEBUG;
195 0 return $self->cached_content->{'details'}->{$account_number};
196 }
197  
198 # initilizes WWW::Mech object, uses it to get to summary page
199 # summary page is cached/overwritten
200 sub login {
201 6 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
202 0 ▶ local $^W = 0;
Subroutine login: not called CC=14 SCAR=53.5
Pod undocumented
203 0 my $self = shift;
204 0 my %p = @_;
205
206 0 ▶ my $start = $p{'start_url'} || $self->start_url();
Condition0%0/3
$p{'start_url'} || $self->start_url
l!l&&r!l&&!r
000
MC/DC0%0/2
$p{'start_url'} || $self->start_url
$p{'start_url'} $self->start_url
Truth table0%0/3
A || B
A= $p{'start_url'}B= $self->start_url
ABresult
1X1
011
000
207 0 ▶ print STDERR "Starting Login (1)\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $DEBUG 0 0 0
208  
209 # now we can get to business
210 0 my $mech = WWW::Mechanize->new(
211 autocheck => 1,
212 max_redirect => 1,
213 );
214
215 # caches the mech object
216 0 $self->mech( $mech );
217  
218 0 $mech->cookie_jar(HTTP::Cookies->new()); # have to turn on cookies manually apparently
219 0 $mech->agent_alias( 'Mac Safari' ); # don't want the bank to know we are geniuses, (using perl)
220 # but we don't want them thinking we are dumb either (using MSIE).
221 # considering changing this to Firefox (mozilla), as a practice in trivialness
222  
223 # make first contact
224 # TODO: add in success checking
225 0 $mech->get( $start );
226 0 ▶ print STDERR "Login (2) Content:\n",
Branch: 1 branch
BranchTrueFalseTotal
if $DEBUG 0 0 0
227 "============ BEGIN CONTENT ===============\n",
228 $mech->content(), "\n",
229 "============ END CONTENT =================\n" if $DEBUG;
230  
231 # the website uses javascript to set this cookie, so we have to do it manually.
232 # without this, an error is returned from the website about either javascript or cookies being turned off
233 0 $mech->cookie_jar->set_cookie( undef, 'CookiesAreEnabled', 'yes', '/', '.wachovia.com', undef, undef, 1 );
234 #$mech->max_redirect(1);
235 #$mech->requests_redirectable([]);
236 0 ▶ if( ! $self->user_id ){
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->user_id) { } 0 0 0
237 0 ▶ print STDERR "Logging in via CAN method...\n" if $DEBUG || $CONFIRM_LOGIN;
Branch: 1 branch
BranchTrueFalseTotal
if $DEBUG or $CONFIRM_LOGIN 0 0 0
Condition0%0/3
$DEBUG or $CONFIRM_LOGIN
l!l&&r!l&&!r
000
MC/DC0%0/2
$DEBUG or $CONFIRM_LOGIN
$DEBUG $CONFIRM_LOGIN
Truth table0%0/3
A or B
A= $DEBUGB= $CONFIRM_LOGIN
ABresult
1X1
011
000
238 0 ▶ print STDERR
Branch: 1 branch
BranchTrueFalseTotal
if $CONFIRM_LOGIN 0 0 0
239 "CAN => '", $self->customer_access_number, "'\n",
240 "PIN => '", $self->pin, "'\n",
241 "CODEWORD => '", $self->code_word, "'\n"
242 if $CONFIRM_LOGIN;
243 0 $mech->form_name( 'canAuthForm' );
244 0 $mech->field( action => 'canPinLogin' );
245 0 $mech->field( CAN => $self->customer_access_number );
246 0 $mech->field( PIN => $self->pin );
247 0 $mech->field( CODEWORD => $self->code_word );
248 0 $mech->field( systemtarget => 'gotoBanking' );
249 0 $mech->field( requestTimestamp => time() ); # the website uses javascript to set this value
250 }
251 else{
252 0 ▶ print STDERR "Logging in via USERID method...\n" if $DEBUG || $CONFIRM_LOGIN;
Branch: 1 branch
BranchTrueFalseTotal
if $DEBUG or $CONFIRM_LOGIN 0 0 0
Condition0%0/3
$DEBUG or $CONFIRM_LOGIN
l!l&&r!l&&!r
000
MC/DC0%0/2
$DEBUG or $CONFIRM_LOGIN
$DEBUG $CONFIRM_LOGIN
Truth table0%0/3
A or B
A= $DEBUGB= $CONFIRM_LOGIN
ABresult
1X1
011
000
253 0 ▶ print STDERR
Branch: 1 branch
BranchTrueFalseTotal
if $CONFIRM_LOGIN 0 0 0
254 "userid => '", $self->user_id, "'\n",
255 "password => '", $self->password, "'\n",
256 if $CONFIRM_LOGIN;
257 0 $mech->form_name( 'uidAuthForm' );
258 0 $mech->field( action => 'uidLogin' );
259 0 $mech->field( userid => $self->user_id );
260 0 $mech->field( password => $self->password );
261 0 $mech->field( systemtarget => 'gotoBanking' );
262 0 $mech->field( requestTimestamp => time() ); # the website uses javascript to set this value
263 }
264 0 $mech->submit();
265 0 ▶ print STDERR "Login (3) Content:\n",
Branch: 1 branch
BranchTrueFalseTotal
if $DEBUG 0 0 0
266 "============ BEGIN CONTENT ===============\n",
267 $mech->content(), "\n",
268 "============ END CONTENT =================\n" if $DEBUG;
269  
270  
271 # after the initial commit, there is what appears to be a bunch of redirects. While there are some, there are
272 # also some javascript onLoad submits. The following code emulates that behavior (just submits a form that
273 # has a bunch of hidden inputs )
274 0 $mech->form_name( 'authForm' );
275 0 $mech->submit();
276 0 ▶ print STDERR "Login (4) Content:\n",
Branch: 1 branch
BranchTrueFalseTotal
if $DEBUG 0 0 0
277 "============ BEGIN CONTENT ===============\n",
278 $mech->content(), "\n",
279 "============ END CONTENT =================\n" if $DEBUG;
280  
281 0 $mech->form_name( 'autoposterForm' );
282 0 $mech->submit();
283 0 ▶ print STDERR "Login (5) Content:\n",
Branch: 1 branch
BranchTrueFalseTotal
if $DEBUG 0 0 0
284 "============ BEGIN CONTENT ===============\n",
285 $mech->content(), "\n",
286 "============ END CONTENT =================\n" if $DEBUG;
287  
288
289 0 $self->cached_content->{'summary'} = $mech->content();
290 0 $self->logged_in( 1 );
291 0 return $self;
292 }
293  
294 ▶sub DESTROY {}
Subroutine DESTROY: not called CC=1 SCAR=0.0
↑ Summary lib/Finance/Bank/Wachovia/Account.pm »