File Coverage

blib/lib/Finance/Bank/Wachovia.pm
Criterion Covered Total %
statement 79 80 98.7
branch 13 18 72.2
condition 8 15 53.3
subroutine 22 23 95.6
pod 5 5 100.0
total 127 141 90.0


line stmt bran cond sub pod time code
1             package Finance::Bank::Wachovia;
2              
3 2     2   1906 use Finance::Bank::Wachovia::ErrorHandler;
  2         4  
  2         50  
4 2     2   689 use Finance::Bank::Wachovia::Account;
  2         5  
  2         53  
5 2     2   968 use Finance::Bank::Wachovia::Credit;
  2         7  
  2         48  
6 2     2   696 use Finance::Bank::Wachovia::Transaction;
  2         4  
  2         49  
7 2     2   766 use Finance::Bank::Wachovia::DataObtainer::WWW;
  2         7  
  2         56  
8 2     2   12 use strict;
  2         3  
  2         32  
9 2     2   8 use warnings;
  2         2  
  2         179  
10              
11             our $VERSION = '0.3';
12             my @attrs;
13             our @ISA = qw/Finance::Bank::Wachovia::ErrorHandler/;
14              
15             BEGIN{
16 2     2   19 @attrs = qw(
17             customer_access_number
18             pin
19             code_word
20             user_id
21             password
22             accounts
23             data_obtainer
24             );
25            
26 2         5 my $x = @__SUPER__::ATTRIBUTES;
27 2         4 for( @attrs ){
28 14     14   373 eval "sub _$_ { $x }";
  14     8   42  
  8     8   30  
  8     20   56  
  20     10   50  
  10     8   38  
  8     14   33  
  14         81  
29 14         354 $x++;
30             }
31             }
32              
33             sub new {
34 4     4 1 1370 my($class, %attrs) = @_;
35 4         8 my $self = [];
36 4         8 bless $self, $class;
37 4         12 foreach my $att ( keys %attrs ){
38 10         50 $self->$att( $attrs{$att} );
39             }
40 4 50 66     18 unless( ( $self->user_id && $self->password ) || ( $self->customer_access_number && $self->pin && $self->code_word ) ){
      33        
      33        
      66        
41 0         0 return Finance::Bank::Wachovia->Error( "Must use either user_id/password OR customer_access_number/pin/code_word" );
42             }
43 4 100 66     15 my %login_info = ( $self->user_id && $self->password )
44             ? ( user_id => $self->user_id, password => $self->password )
45             : ( customer_access_number => $self->customer_access_number, pin => $self->pin, code_word => $self->code_word );
46 4         17 my $data_obtainer = Finance::Bank::Wachovia::DataObtainer::WWW->new(
47             %login_info
48             );
49 4         20 $self->data_obtainer( $data_obtainer );
50 4         21 $self->accounts({});
51 4         12 return $self;
52             }
53              
54              
55             sub AUTOLOAD {
56 2     2   12 no strict 'refs';
  2         3  
  2         834  
57 82     82   115 our $AUTOLOAD;
58 82         97 my $self = shift;
59 82         130 my $attr = lc $AUTOLOAD;
60 82         268 $attr =~ s/.*:://;
61 82 50       749 return $self->Error("$attr not a valid attribute")
62             unless grep /$attr/, @attrs;
63             # get if no args passed
64 82 100       196 return $self->[ &{"_$attr"} ] unless @_;
  64         1180  
65             # set if args passed
66 18         29 $self->[ &{"_$attr"} ] = shift;
  18         349  
67 18         29 return $self;
68             }
69              
70             sub account_numbers {
71 6     6 1 15 my $self = shift;
72 6         20 my $do = $self->data_obtainer();
73 6         15 return $do->get_account_numbers();
74             }
75              
76             sub account_names {
77 2     2 1 8 my $self = shift;
78 2         8 my $do = $self->data_obtainer();
79 2         5 return map { $do->get_account_name($_) } $self->account_numbers();
  4         12  
80             }
81              
82             sub account_balances {
83 2     2 1 8 my $self = shift;
84 2         8 my $do = $self->data_obtainer();
85 2         5 return map { $do->get_account_available_balance($_) } $self->account_numbers();
  4         11  
86             }
87              
88             sub account {
89 5     5 1 5006 my($self, $account_number) = @_;
90 5 100       23 if( exists $self->accounts->{$account_number} ){
91 1         4 return $self->accounts->{$account_number};
92             }
93 4 50       18 return $self->Error("must pass valid account number to account(), got '$account_number'")
94             unless $account_number =~ /^\d+$/;
95 4         16 my $do = $self->data_obtainer();
96 4         7 my $account;
97             #note: we don't set posted_balance here, since that requires extra
98             # work by the obtainer, we defer the retrieval of that until it's
99             # needed (asked for via $account->posted_balance)
100 4 100       11 if( $account_number =~ /\d{16}/ ){ # must be credit?
101 1 50       9 $account = Finance::Bank::Wachovia::Credit->new(
102             number => $account_number,
103             data_obtainer => $do,
104             )
105             or return Error( "Couldn't create Credit object: ".Finance::Bank::Wachovia::Credit->ErrStr );
106            
107             }
108             else{ # must be checkings or savings?
109 3 50       19 $account = Finance::Bank::Wachovia::Account->new(
110             number => $account_number,
111             data_obtainer => $do,
112             )
113             or return Error( "Couldn't create Account object: ".Finance::Bank::Wachovia::Account->ErrStr );
114             }
115 4         15 $self->accounts->{$account_number} = $account;
116 4         16 return $account;
117             }
118              
119       0     sub DESTROY {}
120              
121             __END__