| 1 | =encoding utf8 | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | =head1 NAME | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | Finance::Bank::JP::Mizuho | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | my $mizuho = Finance::Bank::JP::Mizuho-new( | ||||||||||||||||||||||||||||
| 10 | consumer_id => '123455678', | ||||||||||||||||||||||||||||
| 11 | password => 'p45sW0rD', | ||||||||||||||||||||||||||||
| 12 | questions => { | ||||||||||||||||||||||||||||
| 13 | '母親の誕生日はいつですか(例:5月14日)' => '10月1日', # have to use 2byte digits, sucks | ||||||||||||||||||||||||||||
| 14 | '最も年齢の近い兄弟姉妹の誕生日はいつですか(例:2月10日)' => '12月2日', | ||||||||||||||||||||||||||||
| 15 | '応援しているスポーツチームの名前は何ですか' => '阪神タイガース', | ||||||||||||||||||||||||||||
| 16 | }, | ||||||||||||||||||||||||||||
| 17 | ); | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | my $accounts = $mizuho->accounts; | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | my $ofx = $mizuho->get_ofx( | ||||||||||||||||||||||||||||
| 22 | $mizuho->accounts->[0], | ||||||||||||||||||||||||||||
| 23 | $mizuho->CONTINUATION_FROM_LAST, | ||||||||||||||||||||||||||||
| 24 | ); | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | Perl interface to access your L<Mizuho Direct|http://www.mizuhobank.co.jp/direct/start.html> account. | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | =head1 CONSTANT | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | =head2 CONTINUATION_FROM_LAST | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | Value for L</get_ofx> | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | =head2 SAME_AS_LAST | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | Value for L</get_ofx> | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | =head2 LAST_TWO_MONTHS | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | Value for L</get_ofx> | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | =head1 FUNCTIONS | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | =cut | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | package Finance::Bank::JP::Mizuho; | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 52 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 3 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 55 | 3 | ▶ | use DateTime; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 56 | 3 | ▶ | use Encode; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 57 | 3 | ▶ | use Finance::Bank::JP::Mizuho::Account; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 58 | 3 | ▶ | use Finance::OFX::Parse::Simple; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 59 | 3 | ▶ | use HTTP::Cookies; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 60 | 3 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 3 | our $VERSION = '0.02'; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 3 | ▶ | use constant USER_AGENT => 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 65 | 3 | ▶ | use constant START_URL => 'http://www.mizuhobank.co.jp/direct/start.html'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 66 | 3 | ▶ | use constant ENCODING => 'shift_jis'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 3 | ▶ | use constant CONTINUATION_FROM_LAST => 1; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 69 | 3 | ▶ | use constant SAME_AS_LAST => 2; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 70 | 3 | ▶ | use constant LAST_TWO_MONTHS => 3; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | =head2 new ( %config ) | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | Creates a new instance. | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | C<%config> keys: | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | =over 3 | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | =item | ||||||||||||||||||||||||||||
| 81 | B<consumer_id> | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | Consumer id of Mizuho Direct ( お客さま番号 ) | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | =item | ||||||||||||||||||||||||||||
| 86 | B<password> | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | Password for your consumer_id | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | =item | ||||||||||||||||||||||||||||
| 91 | B<questions> | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | Hash reference paired with: Key as Question, Value as Answer | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | =back | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | =cut | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 3 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 100 | 3 | my $class = shift; | |||||||||||||||||||||||||||
| 101 | 3 | my $self = bless { @_ }, $class; | |||||||||||||||||||||||||||
| 102 | 3 | $self; | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | =head2 consumer_id | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | =cut | ||||||||||||||||||||||||||||
| 108 | 2 | ▶ | sub consumer_id { shift->{consumer_id} } | ||||||||||||||||||||||||||
|
Subroutine
consumer_id: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | =head2 accounts | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | returns array of L<Finance::Bank::JP::Mizuho::Account> | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | =cut | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 5 | ▶ | sub accounts { | ||||||||||||||||||||||||||
|
Subroutine
accounts: called CC=3 SCAR=16.5
Pod
documented
| |||||||||||||||||||||||||||||
| 117 | 5 | my $self = shift; | |||||||||||||||||||||||||||
| 118 | 5 | ▶ | return $self->{accounts} if $self->{accounts}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | 0 | ▶ | return [] unless $self->login; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | 0 | $self->parse_accounts( $self->get_content( $self->list_url ) ); | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | =head2 account_by_number ( $number ) | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | returns an instance of L<Finance::Bank::JP::Mizuho::Account> | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | =cut | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 1 | ▶ | sub account_by_number { | ||||||||||||||||||||||||||
|
Subroutine
account_by_number: called CC=5 SCAR=17.5
Pod
documented
| |||||||||||||||||||||||||||||
| 130 | 1 | my ( $self, $number ) = @_; | |||||||||||||||||||||||||||
| 131 | 1 | my @accounts = @{ $self->accounts }; | |||||||||||||||||||||||||||
| 132 | 1 | ▶ | return unless @accounts && $number; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@accounts and $number
MC/DC0%0/2
@accounts and $number
@accounts
$number
Truth table33%1/3
A and B
A= @accountsB= $number
| |||||||||||||||||||||||||||||
| 133 | 1 | foreach my $account ( @accounts ) { | |||||||||||||||||||||||||||
| 134 | 1 | ▶ | return $account if $account->number eq $number; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | =head2 get_ofx ( $account_or_number , $term ) | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | C<$account_or_number>: | ||||||||||||||||||||||||||||
| 141 | an instance of L<Finance::Bank::JP::Mizuho::Account> OR bank account number | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | C<$term> : | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | =over 3 | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | =item L</CONTINUATION_FROM_LAST> | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | =item L</SAME_AS_LAST> | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | =item L</LAST_TWO_MONTHS> | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | =back | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | returns list of hash references, parsed by L<Finance::OFX::Parse::Simple> | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | =cut | ||||||||||||||||||||||||||||
| 158 | 0 | ▶ | sub get_ofx { | ||||||||||||||||||||||||||
|
Subroutine
get_ofx: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 159 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 0 | Finance::OFX::Parse::Simple->parse_scalar($self->get_raw_ofx(@_)); | |||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | =head2 get_raw_ofx ( $account_or_number , $term ) | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | arguments are same as L</get_ofx>. | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | returns OFX content as scalar | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | =cut | ||||||||||||||||||||||||||||
| 171 | 0 | ▶ | sub get_raw_ofx { | ||||||||||||||||||||||||||
|
Subroutine
get_raw_ofx: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||
| 172 | 0 | my ($self, $account, $term) = @_; | |||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 0 | ▶ | $term ||= CONTINUATION_FROM_LAST; | ||||||||||||||||||||||||||
|
Condition0%0/2
$term ||= 1
MC/DC0%0/1
$term ||= 1
$term
Truth table0%0/2
A
A= $term
| |||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | 0 | ▶ | if( $term !~ /^(1|2|3)$/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 177 | 0 | carp( 'Invalid value to $term:'. $term ); | |||||||||||||||||||||||||||
| 178 | 0 | return 0; | |||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | 0 | my $val; | |||||||||||||||||||||||||||
| 182 | 0 | ▶ | $account = $self->account_by_number( $account ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 183 | if( ref($account) ne 'Finance::Bank::JP::Mizuho::Account' ); | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | 0 | ▶ | unless( $account ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 186 | 0 | carp( 'No account' ); | |||||||||||||||||||||||||||
| 187 | 0 | return 0; | |||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | 0 | $self->get_content( $self->ref_url ); | |||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | 0 | my $content = $self->get_content( $self->list_url ); | |||||||||||||||||||||||||||
| 193 | 0 | my $emfpostkey = $self->emfpostkey( $content ); | |||||||||||||||||||||||||||
| 194 | 0 | my $action = $self->form1_action( $content ); | |||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | 0 | ▶ | unless( $emfpostkey && $action ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$emfpostkey and $action
MC/DC0%0/2
$emfpostkey and $action
$emfpostkey
$action
Truth table0%0/3
A and B
A= $emfpostkeyB= $action
| |||||||||||||||||||||||||||||
| 197 | 0 | carp( 'Failed to parse page' ); | |||||||||||||||||||||||||||
| 198 | 0 | return 0; | |||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | 0 | my $res = $self->ua->post( | |||||||||||||||||||||||||||
| 202 | $action, | ||||||||||||||||||||||||||||
| 203 | Referer => $self->list_url, | ||||||||||||||||||||||||||||
| 204 | Content => [ | ||||||||||||||||||||||||||||
| 205 | Token => '', | ||||||||||||||||||||||||||||
| 206 | REDISP => 'OFF', | ||||||||||||||||||||||||||||
| 207 | NLS => 'JP', | ||||||||||||||||||||||||||||
| 208 | EMFPOSTKEY => $emfpostkey, | ||||||||||||||||||||||||||||
| 209 | SelectRadio => $account->radio_value, | ||||||||||||||||||||||||||||
| 210 | DownhaniBox => $term, | ||||||||||||||||||||||||||||
| 211 | Next => 'Yippee!', | ||||||||||||||||||||||||||||
| 212 | ], | ||||||||||||||||||||||||||||
| 213 | ); | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | 0 | my $dest = $res->header('location'); | |||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | 0 | ▶ | unless( $dest ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 218 | 0 | carp( 'Query fail' ); | |||||||||||||||||||||||||||
| 219 | 0 | return 0; | |||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | 0 | $content = $self->get_content( $dest ); | |||||||||||||||||||||||||||
| 223 | 0 | $emfpostkey = $self->emfpostkey( $content ); | |||||||||||||||||||||||||||
| 224 | 0 | $action = $self->form1_action( $content ); | |||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | 0 | $res = $self->ua->post( | |||||||||||||||||||||||||||
| 227 | $action, | ||||||||||||||||||||||||||||
| 228 | Referer => $action, | ||||||||||||||||||||||||||||
| 229 | Content => [ | ||||||||||||||||||||||||||||
| 230 | Token => '', | ||||||||||||||||||||||||||||
| 231 | NLS => 'JP', | ||||||||||||||||||||||||||||
| 232 | EMFPOSTKEY => $emfpostkey, | ||||||||||||||||||||||||||||
| 233 | ], | ||||||||||||||||||||||||||||
| 234 | ); | ||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | 0 | $dest = $res->header('location'); | |||||||||||||||||||||||||||
| 237 | 0 | ▶ | unless( $dest ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 238 | 0 | carp( 'Query fail' ); | |||||||||||||||||||||||||||
| 239 | 0 | return 0; | |||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | 0 | $content = $self->get_content( $dest ); | |||||||||||||||||||||||||||
| 243 | 0 | $emfpostkey = $self->emfpostkey( $content ); | |||||||||||||||||||||||||||
| 244 | 0 | $action = $self->form1_action( $content ); | |||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | 0 | my $ofx = $self->ua->get( $self->ofx_url )->content; | |||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | 0 | $res = $self->ua->post( | |||||||||||||||||||||||||||
| 249 | $action, | ||||||||||||||||||||||||||||
| 250 | Referer => $action, | ||||||||||||||||||||||||||||
| 251 | Content => [ | ||||||||||||||||||||||||||||
| 252 | Token => '', | ||||||||||||||||||||||||||||
| 253 | NLS => 'JP', | ||||||||||||||||||||||||||||
| 254 | EMFPOSTKEY => $emfpostkey, | ||||||||||||||||||||||||||||
| 255 | ], | ||||||||||||||||||||||||||||
| 256 | ); | ||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | 0 | $ofx | |||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | =head2 host | ||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | returns random host, provided by Mizuho Direct web service. | ||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||
| 265 | =cut | ||||||||||||||||||||||||||||
| 266 | 4 | ▶ | sub host { | ||||||||||||||||||||||||||
|
Subroutine
host: called CC=4 SCAR=17.2
Pod
documented
| |||||||||||||||||||||||||||||
| 267 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 268 | 4 | ▶ | if(@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 269 | 0 | my $host = shift; | |||||||||||||||||||||||||||
| 270 | 0 | $self->ua->default_headers->header( | |||||||||||||||||||||||||||
| 271 | Origin => "https://$host", | ||||||||||||||||||||||||||||
| 272 | Host => $host, | ||||||||||||||||||||||||||||
| 273 | ); | ||||||||||||||||||||||||||||
| 274 | 0 | $self->{host} = $host; | |||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||
| 276 | 4 | ▶ | return $self->{host} if $self->{host}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 277 | 4 | ▶ | $self->{host} || 'web.ib.mizuhobank.co.jp' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||
| 281 | =head2 logged_in | ||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||
| 283 | returns this instance has logged in | ||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||
| 285 | =cut | ||||||||||||||||||||||||||||
| 286 | 6 | ▶ | sub logged_in { | ||||||||||||||||||||||||||
|
Subroutine
logged_in: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 287 | 6 | my $self = shift; | |||||||||||||||||||||||||||
| 288 | 6 | ▶ | $self->{logged_in} = shift if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 289 | 6 | $self->{logged_in}; | |||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||
| 293 | =head2 login | ||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||
| 295 | returns logged in successfully. | ||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||
| 297 | calling this method is not neccesary. | ||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||
| 299 | =cut | ||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||
| 301 | 0 | ▶ | sub login { | ||||||||||||||||||||||||||
|
Subroutine
login: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 302 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 303 | 0 | ▶ | return 1 if $self->logged_in; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 304 | 0 | my $url = $self->login_url2; | |||||||||||||||||||||||||||
| 305 | 0 | ▶ | ($url=~m{xtr=Emf00005}) ? | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 306 | $self->_login($url) : | ||||||||||||||||||||||||||||
| 307 | $self->_question($url); | ||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||
| 310 | =head2 logout | ||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||
| 312 | if you leave the process without calling this method, | ||||||||||||||||||||||||||||
| 313 | the account will be locked for about 10 minutes, | ||||||||||||||||||||||||||||
| 314 | and you will not able to access the web service. | ||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||
| 316 | =cut | ||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||
| 318 | 2 | ▶ | sub logout { | ||||||||||||||||||||||||||
|
Subroutine
logout: called CC=2 SCAR=9.2
Pod
documented
| |||||||||||||||||||||||||||||
| 319 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 320 | 2 | ▶ | return unless $self->logged_in; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 321 | 0 | my $res = $self->ua->get($self->logout_url); | |||||||||||||||||||||||||||
| 322 | 0 | $self->logged_in(0); | |||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||
| 325 | =head2 password | ||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||
| 327 | =cut | ||||||||||||||||||||||||||||
| 328 | 0 | ▶ | sub password { shift->{password} } | ||||||||||||||||||||||||||
|
Subroutine
password: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||
| 330 | =head2 questions | ||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||
| 332 | =cut | ||||||||||||||||||||||||||||
| 333 | 0 | ▶ | sub questions { shift->{questions} } | ||||||||||||||||||||||||||
|
Subroutine
questions: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||
| 335 | =head2 ua | ||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||
| 337 | =cut | ||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||
| 339 | 3 | ▶ | sub ua { | ||||||||||||||||||||||||||
|
Subroutine
ua: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||||
| 340 | 3 | ▶ | shift->{ua} ||= LWP::UserAgent->new( | ||||||||||||||||||||||||||
|
Condition66%2/3
+(shift())->{"ua"} ||= "LWP::UserAgent"->new("agent", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)", "cookie_jar", "HTTP::Cookies"->new, "max_redirect", 0, "requests_redirectable", [])
MC/DC0%0/2
+(shift())->{"ua"} ||= "LWP::UserAgent"->new("agent", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)", "cookie_jar", "HTTP::Cookies"->new, "max_redirect", 0, "requests_redirectable", [])
+(shift())->{"ua"}
"LWP::UserAgent"->new("agent", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)", "cookie_jar", "HTTP::Cookies"->new, "max_redirect", 0, "requests_redirectable", [])
Truth table66%2/3
A ||= B
A= +(shift())->{"ua"}B= "LWP::UserAgent"->new("agent", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)", "cookie_jar", "HTTP::Cookies"->new, "max_redirect", 0, "requests_redirectable", [])
| |||||||||||||||||||||||||||||
| 341 | agent => USER_AGENT, | ||||||||||||||||||||||||||||
| 342 | cookie_jar => HTTP::Cookies->new, | ||||||||||||||||||||||||||||
| 343 | max_redirect => 0, | ||||||||||||||||||||||||||||
| 344 | requests_redirectable => [], | ||||||||||||||||||||||||||||
| 345 | ) | ||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||
| 348 | ## private __________________________________________________________________________________________ | ||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||
| 350 | 2 | ▶ | sub login_url1 { 'https://'. shift->host .'/servlet/mib?xtr=Emf00000' } | ||||||||||||||||||||||||||
|
Subroutine
login_url1: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 351 | 1 | ▶ | sub logout_url { 'https://'. shift->host . ':443/servlet/mib?xtr=EmfLogOff&NLS=JP' } | ||||||||||||||||||||||||||
|
Subroutine
logout_url: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 352 | 0 | ▶ | sub ref_url { 'https://'. shift->host . '/servlet/mib?xtr=Emf04000&NLS=JP' } | ||||||||||||||||||||||||||
|
Subroutine
ref_url: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 353 | 1 | ▶ | sub list_url { 'https://'. shift->host . '/servlet/mib?xtr=Emf04610&NLS=JP' } | ||||||||||||||||||||||||||
|
Subroutine
list_url: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 354 | 0 | ▶ | sub ofx_url { 'https://'. shift->host . ':443/servlet/mib?xtr=Emf04625' } | ||||||||||||||||||||||||||
|
Subroutine
ofx_url: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||
| 356 | 1 | ▶ | sub login_url2 { | ||||||||||||||||||||||||||
|
Subroutine
login_url2: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 357 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 358 | 1 | my $action = $self->form1_action($self->get_content($self->login_url1)); | |||||||||||||||||||||||||||
| 359 | 1 | my $res = $self->ua->post( $action, [ | |||||||||||||||||||||||||||
| 360 | pm_fp => '', | ||||||||||||||||||||||||||||
| 361 | KeiyakuNo => $self->consumer_id, | ||||||||||||||||||||||||||||
| 362 | Next => 'Yippee!', | ||||||||||||||||||||||||||||
| 363 | ]); | ||||||||||||||||||||||||||||
| 364 | 1 | ▶ | my $url = $res->header('location') || ''; | ||||||||||||||||||||||||||
|
Condition50%1/2
$res->header('location') || ''
MC/DC0%0/1
$res->header('location') || ''
$res->header('location')
Truth table50%1/2
A
A= $res->header('location')
| |||||||||||||||||||||||||||||
| 365 | 1 | ▶ | $self->host($1) if $url =~ m%^https://([^/\:]+).*%; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 366 | 1 | $url; | |||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||
| 369 | 0 | ▶ | sub _question { | ||||||||||||||||||||||||||
|
Subroutine
_question: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 370 | 0 | my ($self,$url) = @_; | |||||||||||||||||||||||||||
| 371 | 0 | my $content = $self->get_content($url); | |||||||||||||||||||||||||||
| 372 | 0 | my $action = $self->form1_action($content); | |||||||||||||||||||||||||||
| 373 | 0 | my ( $question, $answer ); | |||||||||||||||||||||||||||
| 374 | 0 | ▶ | unless( $question = $self->parse_question($content) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 375 | 0 | carp('Failed to parse question screen'); | |||||||||||||||||||||||||||
| 376 | 0 | return 0; | |||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||
| 378 | 0 | ▶ | unless( $answer = $self->questions->{$question} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 379 | 0 | carp("No answer for '$question'"); | |||||||||||||||||||||||||||
| 380 | 0 | return 0; | |||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||
| 382 | 0 | my $res = $self->ua->post( $action, [ | |||||||||||||||||||||||||||
| 383 | rskAns => encode(ENCODING, decode('utf8', $answer) ), | ||||||||||||||||||||||||||||
| 384 | Next => 'Yippee!', | ||||||||||||||||||||||||||||
| 385 | NLS => 'JP', | ||||||||||||||||||||||||||||
| 386 | Token => '', | ||||||||||||||||||||||||||||
| 387 | jsAware => 'on', | ||||||||||||||||||||||||||||
| 388 | frmScrnID => 'Emf00000', | ||||||||||||||||||||||||||||
| 389 | ]); | ||||||||||||||||||||||||||||
| 390 | 0 | my $dest = $res->header('location'); | |||||||||||||||||||||||||||
| 391 | 0 | ▶ | unless($dest) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 392 | 0 | carp('Login failure'); | |||||||||||||||||||||||||||
| 393 | 0 | return 0; | |||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||
| 395 | 0 | ▶ | $dest eq $url ? | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 396 | $self->_question($url) : | ||||||||||||||||||||||||||||
| 397 | $self->_login($dest); | ||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||
| 400 | 0 | ▶ | sub _login { | ||||||||||||||||||||||||||
|
Subroutine
_login: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 401 | 0 | my ($self,$url) = @_; | |||||||||||||||||||||||||||
| 402 | 0 | my $content = $self->get_content($url); | |||||||||||||||||||||||||||
| 403 | 0 | my $action = $self->form1_action($content); | |||||||||||||||||||||||||||
| 404 | 0 | my $res = $self->ua->post( $action, [ | |||||||||||||||||||||||||||
| 405 | NLS => 'JP', | ||||||||||||||||||||||||||||
| 406 | jsAware => 'on', | ||||||||||||||||||||||||||||
| 407 | pmimg => '0', | ||||||||||||||||||||||||||||
| 408 | Anshu1No => $self->password, | ||||||||||||||||||||||||||||
| 409 | login => 'Yippee!', | ||||||||||||||||||||||||||||
| 410 | ]); | ||||||||||||||||||||||||||||
| 411 | 0 | my $dest = $res->header('location'); | |||||||||||||||||||||||||||
| 412 | 0 | ▶ | return 0 unless $dest; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 413 | 0 | $self->logged_in(1); | |||||||||||||||||||||||||||
| 414 | 0 | 1 | |||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||
| 417 | 1 | ▶ | sub parse_question { | ||||||||||||||||||||||||||
|
Subroutine
parse_question: called CC=3 SCAR=13.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 418 | 1 | my ($self,$content) = @_; | |||||||||||||||||||||||||||
| 419 | 1 | ▶ | return $1 if( ( $content || '' ) =~ /.*<TD width="200" align="right"><DIV style="font-size:9pt">.+[^\n\r]*[\n\r].*<DIV[^>]*>([^<]+)<.*/i ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$content || ''
MC/DC0%0/1
$content || ''
$content
Truth table50%1/2
A
A= $content
| |||||||||||||||||||||||||||||
| 420 | 0 | '' | |||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||
| 423 | 1 | ▶ | sub parse_accounts { | ||||||||||||||||||||||||||
|
Subroutine
parse_accounts: called CC=8 SCAR=21.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 424 | 1 | my ($self,$content) = @_; | |||||||||||||||||||||||||||
| 425 | 1 | $content =~ s/[\s"\r\n\t]//g; | |||||||||||||||||||||||||||
| 426 | 1 | my $re = | |||||||||||||||||||||||||||
| 427 | q{<TDwidth=30[^>]*><INPUT.*NAME=SelectRadio.*value=(\d+)[^>]*></TD>}. | ||||||||||||||||||||||||||||
| 428 | q{<TDwidth=150[^>]*><DIV[^>]*> ([^<]+)</DIV></TD>}. | ||||||||||||||||||||||||||||
| 429 | q{<TDwidth=100[^>]*><DIV[^>]*> ([^<]+)</DIV></TD>}. | ||||||||||||||||||||||||||||
| 430 | q{<TDwidth=100[^>]*><DIV[^>]*>(\d+)</DIV></TD>}. | ||||||||||||||||||||||||||||
| 431 | q{<TDwidth=190[^>]*><DIV[^>]*>([^<]+)</DIV></TD>}; | ||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||
| 433 | 1 | my @tr = split /TR><TR/i, $content; | |||||||||||||||||||||||||||
| 434 | 1 | my @accounts = (); | |||||||||||||||||||||||||||
| 435 | 1 | my $tz = 'Asia/Tokyo'; | |||||||||||||||||||||||||||
| 436 | 1 | foreach my $t (@tr) { | |||||||||||||||||||||||||||
| 437 | 3 | ▶ | if($t =~ /$re/i) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 438 | 3 | my $obj = { | |||||||||||||||||||||||||||
| 439 | radio_value => $1, | ||||||||||||||||||||||||||||
| 440 | branch => $2, | ||||||||||||||||||||||||||||
| 441 | type => $3, | ||||||||||||||||||||||||||||
| 442 | number => $4, | ||||||||||||||||||||||||||||
| 443 | }; | ||||||||||||||||||||||||||||
| 444 | 3 | my $d = $5; | |||||||||||||||||||||||||||
| 445 | 3 | my ($start, $end); | |||||||||||||||||||||||||||
| 446 | 3 | ▶ | if( $d =~ /(\d{4})\.(\d{2})\.(\d{2})[^\d]+(\d{4})\.(\d{2})\.(\d{2})/ ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 447 | 2 | $start = DateTime->new( | |||||||||||||||||||||||||||
| 448 | year => $1, | ||||||||||||||||||||||||||||
| 449 | month => $2, | ||||||||||||||||||||||||||||
| 450 | day => $3, | ||||||||||||||||||||||||||||
| 451 | time_zone => $tz, | ||||||||||||||||||||||||||||
| 452 | ); | ||||||||||||||||||||||||||||
| 453 | 2 | $end = DateTime->new( | |||||||||||||||||||||||||||
| 454 | year => $4, | ||||||||||||||||||||||||||||
| 455 | month => $5, | ||||||||||||||||||||||||||||
| 456 | day => $6, | ||||||||||||||||||||||||||||
| 457 | time_zone => $tz, | ||||||||||||||||||||||||||||
| 458 | ); | ||||||||||||||||||||||||||||
| 459 | } elsif( $d =~ /(\d{4})\.(\d{2})\.(\d{2})/ ) { | ||||||||||||||||||||||||||||
| 460 | 1 | $start = DateTime->new( | |||||||||||||||||||||||||||
| 461 | year => $1, | ||||||||||||||||||||||||||||
| 462 | month => $2, | ||||||||||||||||||||||||||||
| 463 | day => $3, | ||||||||||||||||||||||||||||
| 464 | time_zone => $tz, | ||||||||||||||||||||||||||||
| 465 | ); | ||||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||
| 467 | 3 | ▶ | $end ||= $start; | ||||||||||||||||||||||||||
|
Condition66%2/3
$end ||= $start
MC/DC0%0/2
$end ||= $start
$end
$start
Truth table66%2/3
A ||= B
A= $endB= $start
| |||||||||||||||||||||||||||||
| 468 | 3 | ▶ | $obj->{last_downloaded_from} = $start if $start; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 469 | 3 | ▶ | $obj->{last_downloaded_to} = $end if $end; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 470 | 3 | push @accounts, Finance::Bank::JP::Mizuho::Account->new(%$obj); | |||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||
| 472 | } | ||||||||||||||||||||||||||||
| 473 | 1 | $self->{accounts} = [@accounts]; | |||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||
| 476 | 3 | ▶ | sub form1_action { | ||||||||||||||||||||||||||
|
Subroutine
form1_action: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 477 | 3 | my ($self,$content) = @_; | |||||||||||||||||||||||||||
| 478 | 3 | ▶ | return $1 if $content =~ /.*action="([^"]+)"[^\n\r]+name="FORM1".*/ig; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 479 | 2 | ▶ | return $1 if $content =~ /.*name="FORM1"[^\n\r]+action="([^"]+)".*/ig; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 480 | 1 | '' | |||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||
| 483 | 0 | ▶ | sub emfpostkey { | ||||||||||||||||||||||||||
|
Subroutine
emfpostkey: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 484 | 0 | my ($self,$content) = @_; | |||||||||||||||||||||||||||
| 485 | 0 | ▶ | return $1 if ( $content =~ /<INPUT.*NAME="EMFPOSTKEY" VALUE="([^"]+)">/i ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 486 | 0 | '' | |||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||
| 489 | 1 | ▶ | sub get_content { | ||||||||||||||||||||||||||
|
Subroutine
get_content: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 490 | 1 | my ($self,$url) = @_; | |||||||||||||||||||||||||||
| 491 | 1 | my $res = $self->ua->get($url); | |||||||||||||||||||||||||||
| 492 | 1 | $self->ua->default_headers->header( Referer => $url ); | |||||||||||||||||||||||||||
| 493 | 1 | encode('utf8', decode(ENCODING,$res->content) ); | |||||||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||
| 499 | 3 | 1 | |||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||
| 501 | __END__ | ||||||||||||||||||||||||||||