blib/lib/Finance/Bank/Fubon/TW.pm | |||
---|---|---|---|
Criterion | Covered | Total | % |
statement | 12 | 52 | 23.0 |
branch | 0 | 8 | 0.0 |
condition | n/a | ||
subroutine | 4 | 7 | 57.1 |
pod | 0 | 1 | 0.0 |
total | 16 | 68 | 23.5 |
line | stmt | bran | cond | sub | pod | time | code | |
---|---|---|---|---|---|---|---|---|
1 | # $File: //member/autrijus/Finance-Bank-Fubon-TW/lib/Finance/Bank/Fubon/TW.pm $ $Author: autrijus $ | |||||||
2 | # $Revision: #2 $ $Change: 5938 $ $DateTime: 2003/05/17 22:34:34 $ | |||||||
3 | ||||||||
4 | package Finance::Bank::Fubon::TW; | |||||||
5 | 1 | 1 | 6833 | use strict; | ||||
1 | 3 | |||||||
1 | 63 | |||||||
6 | 1 | 1 | 6 | use Carp; | ||||
1 | 3 | |||||||
1 | 82 | |||||||
7 | our $VERSION = '0.01'; | |||||||
8 | 1 | 1 | 1431 | use WWW::Mechanize; | ||||
1 | 365189 | |||||||
1 | 375 | |||||||
9 | our $ua = WWW::Mechanize->new( | |||||||
10 | env_proxy => 1, | |||||||
11 | keep_alive => 1, | |||||||
12 | timeout => 60, | |||||||
13 | ); | |||||||
14 | ||||||||
15 | sub check_balance { | |||||||
16 | 0 | 0 | 0 | my ($class, %opts) = @_; | ||||
17 | 0 | local $^W; | ||||||
18 | ||||||||
19 | 0 | 0 | croak "Must provide a password" unless exists $opts{password}; | |||||
20 | 0 | 0 | croak "Must provide a username" unless exists $opts{username}; | |||||
21 | ||||||||
22 | 0 | my $self = bless { %opts }, $class; | ||||||
23 | ||||||||
24 | 0 | $ua->get('https://net.fubonbank.com.tw/ebank/nbssl/nbauth/loginmain.asp'); | ||||||
25 | 0 | $ua->field(USERID => $self->{username}); | ||||||
26 | 0 | $ua->field(PWD => $self->{password}); | ||||||
27 | 0 | $ua->submit; | ||||||
28 | 0 | $ua->get('https://net.fubonbank.com.tw/ebank/nbssl/nbauth/QryMain.asp'); | ||||||
29 | ||||||||
30 | 0 | my $html = $ua->content; | ||||||
31 | ||||||||
32 | 0 | my @accounts; | ||||||
33 | 0 | while ($html =~ s! | ]*>([^<]+) | !!) {|||||
34 | 0 | my ($id, $balance) = ($1, $2); | ||||||
35 | 0 | $balance =~ s!,!!g; | ||||||
36 | 0 | $balance = 0 + $balance; | ||||||
37 | 0 | push @accounts, (bless { | ||||||
38 | balance => $balance, | |||||||
39 | name => $id, | |||||||
40 | account_no => $id, | |||||||
41 | parent => $self, | |||||||
42 | }, "Finance::Bank::Fubon::TW::Account"); | |||||||
43 | } | |||||||
44 | ||||||||
45 | 0 | return @accounts; | ||||||
46 | } | |||||||
47 | ||||||||
48 | package Finance::Bank::Fubon::TW::Account; | |||||||
49 | # Basic OO smoke-and-mirrors Thingy | |||||||
50 | 1 | 1 | 21 | no strict; | ||||
1 | 3 | |||||||
1 | 632 | |||||||
51 | 0 | 0 | sub AUTOLOAD { my $self=shift; $AUTOLOAD =~ s/.*:://; $self->{$AUTOLOAD} } | |||||
0 | ||||||||
0 | ||||||||
52 | ||||||||
53 | sub statement { | |||||||
54 | 0 | 0 | my $ac = shift; | |||||
55 | 0 | my $code; | ||||||
56 | ||||||||
57 | 0 | $ua->get('https://net.fubonbank.com.tw/ebank/Nbssl/asp/VR002Htm.asp?acc=' . $ac->account_no); | ||||||
58 | 0 | $ua->submit; | ||||||
59 | ||||||||
60 | 0 | my $html = $ua->content; | ||||||
61 | 0 | my @transactions; | ||||||
62 | 0 | while ($html =~ s! | ||||||
63 | 0 | my @lines; | ||||||
64 | 0 | foreach my $line (split(/\n/, $1)) { | ||||||
65 | 0 | 0 | next unless $line =~ / | |||||
66 | 0 | $line =~ s/^\s+//; | ||||||
67 | 0 | $line =~ s/\s+$//; | ||||||
68 | 0 | $line =~ s/<[^>]+> ?//g; | ||||||
69 | 0 | $line =~ s/^ $//g; | ||||||
70 | 0 | 0 | if ( $line =~ s/,// ) { | |||||
71 | 0 | $line = 0 + $line; | ||||||
72 | } | |||||||
73 | 0 | push @lines, $line; | ||||||
74 | } | |||||||
75 | 0 | push @transactions, join(',', @lines) . "\n"; | ||||||
76 | } | |||||||
77 | ||||||||
78 | 0 | return join("", @transactions); | ||||||
79 | } | |||||||
80 | ||||||||
81 | 1; | |||||||
82 | ||||||||
83 | __END__ |