OFX.pm

filter: Statementstmt 18.1% 14 / 77 Branchbran 0.0% 0 / 44 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 28.5% 4 / 14 Podpod 80.0% 8 / 10 totaltotal 17.3% 26 / 150 CC 26 SCAR 37.6
CC
26
Cov
11%
transactions
90.0
balance
72.0
accounts
30.0
CRAP 43.0
« OFX/Parse.pm ↑ Summary OFX/Institution.pm »
1 # Filename: OFX.pm
2 # Serialize, Parse and Query using the Open Financial Exchange format
3 # http://www.ofx.net/
4 #
5 # Created January 30, 2008 Brandon Fosdick <bfoz@bfoz.net>
6 #
7 # Copyright 2008 Brandon Fosdick <bfoz@bfoz.net> (BSD License)
8 #
9 # $Id: OFX.pm,v 1.2 2008/03/04 04:22:24 bfoz Exp $
10  
11 package Finance::OFX;
12  
13 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 2 our $VERSION = '2';
17  
18 2 ▶use Finance::OFX::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 2 ▶use HTTP::Date;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 sub new
23 0 ▶{
Subroutine new: not called CC=3 SCAR=24.8
Pod documented
24 0 my ($this, %options) = @_;
25 0 ▶ my $class = ref($this) || $this;
Condition0%0/3
ref $this || $this
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table0%0/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
26 0 my $self = {};
27 0 bless $self, $class;
28  
29 # Assume any unprocessed options are meant for the UserAgent,
30 # which implies that this object will be used to generate and process
31 # requests instead of processing stored files
32 0 ▶ $self->{ua} = Finance::OFX::UserAgent->new(%options) if scalar keys %options;
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %options 0 0 0
33  
34 0 return $self;
35 }
36  
37 # --- Getters and Setters ---
38  
39 sub institution
40 0 ▶{
Subroutine institution: not called CC=1 SCAR=6.9
Pod documented
41 0 my $s = shift;
42 0 $s->{ua}->institution(@_);
43 }
44  
45 sub response
46 0 ▶{
Subroutine response: not called CC=1 SCAR=6.9
Pod documented
47 0 my $s = shift;
48 0 $s->{ua}->{response};
49 }
50  
51 sub user_id
52 0 ▶{
Subroutine user_id: not called CC=1 SCAR=6.9
Pod documented
53 0 my $s = shift;
54 0 $s->{ua}->user_id(@_);
55 }
56  
57 sub user_pass
58 0 ▶{
Subroutine user_pass: not called CC=1 SCAR=6.9
Pod documented
59 0 my $s = shift;
60 0 $s->{ua}->user_pass(@_);
61 }
62  
63 # --- Public Methods ---
64  
65 sub accounts
66 0 ▶{
Subroutine accounts: not called CC=5 SCAR=34.0
Pod documented
67 0 my $s = shift;
68  
69 0 my $r = $s->{ua}->account_info;
70  
71 0 ▶ return -1 unless $r->is_success;
Branch: 1 branch
BranchTrueFalseTotal
unless $r->is_success 0 0 0
72 0 ▶ return -2 if $r->signon_status_code;
Branch: 1 branch
BranchTrueFalseTotal
if $r->signon_status_code 0 0 0
73 0 ▶ return undef unless $r->ofx->{signupmsgsrsv1}{acctinfotrnrs}{acctinfors}{acctinfo};
Branch: 1 branch
BranchTrueFalseTotal
unless $r->ofx->{"signupmsgsrsv1"}{"acctinfotrnrs"}{"acctinfors"}{"acctinfo"} 0 0 0
74  
75 0 my @accounts;
76 0 for( @{$r->ofx->{signupmsgsrsv1}{acctinfotrnrs}{acctinfors}{acctinfo}} )
77 {
78 0 my %b = flatten($_);
79 0 push @accounts, \%b;
80 }
81 0 return @accounts;
82 }
83  
84 sub balance
85 0 ▶{
Subroutine balance: not called CC=8 SCAR=42.8
Pod documented
86 0 my ($s, $acct) = @_;
87 0 ▶ return undef unless ref($acct) eq 'Finance::OFX::Account';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $acct eq "Finance::OFX::Account" 0 0 0
88  
89 # Use the FID from the given FI if none is set in the given Account
90 0 ▶ $acct->fid($s->institution()->fid()) unless $acct->fid();
Branch: 1 branch
BranchTrueFalseTotal
unless $acct->fid 0 0 0
91  
92 0 my $r = $s->{ua}->statement($acct);
93 0 ▶ return -1 unless $r->is_success;
Branch: 1 branch
BranchTrueFalseTotal
unless $r->is_success 0 0 0
94 0 ▶ return -2 if $r->signon_status_code;
Branch: 1 branch
BranchTrueFalseTotal
if $r->signon_status_code 0 0 0
95 0 ▶ return undef unless $r->ofx->{bankmsgsrsv1}{stmttrnrs};
Branch: 1 branch
BranchTrueFalseTotal
unless $r->ofx->{"bankmsgsrsv1"}{"stmttrnrs"} 0 0 0
96  
97 0 my $transaction = $r->ofx->{bankmsgsrsv1}{stmttrnrs};
98 0 ▶ return "Statement request error: ".($transaction->{status}{message}) if transactionStatusCode($transaction);
Branch: 1 branch
BranchTrueFalseTotal
if transactionStatusCode($transaction) 0 0 0
99 0 ▶ return "No statement info returned" unless exists $transaction->{stmtrs};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $transaction->{"stmtrs"} 0 0 0
100  
101 0 return $transaction->{stmtrs};
102 }
103  
104 sub transactions
105 0 ▶{
Subroutine transactions: not called CC=9 SCAR=45.0
Pod documented
106 0 my ($s, $acct, $start, $end) = @_;
107 0 ▶ return undef unless ref($acct) eq 'Finance::OFX::Account';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $acct eq "Finance::OFX::Account" 0 0 0
108  
109 # Use the FID from the given FI if none is set in the given Account
110 0 ▶ $acct->fid($s->institution()->fid()) unless $acct->fid();
Branch: 1 branch
BranchTrueFalseTotal
unless $acct->fid 0 0 0
111  
112 0 my %options;
113 0 $options{transactions} = 'Y';
114 0 ▶ $options{start} = $start if $start;
Branch: 1 branch
BranchTrueFalseTotal
if $start 0 0 0
115 0 ▶ $options{end} = $end if $end;
Branch: 1 branch
BranchTrueFalseTotal
if $end 0 0 0
116  
117 0 my $r = $s->{ua}->statement($acct, %options);
118 0 ▶ return -1 unless $r->is_success;
Branch: 1 branch
BranchTrueFalseTotal
unless $r->is_success 0 0 0
119 0 ▶ return -2 if $r->signon_status_code;
Branch: 1 branch
BranchTrueFalseTotal
if $r->signon_status_code 0 0 0
120 0 my $ofx = $r->ofx;
121 0 ▶ return undef unless $ofx->{bankmsgsrsv1}{stmttrnrs}{stmtrs};
Branch: 1 branch
BranchTrueFalseTotal
unless $ofx->{"bankmsgsrsv1"}{"stmttrnrs"}{"stmtrs"} 0 0 0
122 0 my $transaction = $ofx->{bankmsgsrsv1}{stmttrnrs};
123 0 ▶ return "Statement request error: ".($transaction->{status}{message}) if transactionStatusCode($transaction);
Branch: 1 branch
BranchTrueFalseTotal
if transactionStatusCode($transaction) 0 0 0
124  
125 0 return $transaction->{stmtrs}{banktranlist};
126 }
127  
128 sub transactionStatusCode
129 0 ▶{
Subroutine transactionStatusCode: not called CC=2 SCAR=17.9
Pod undocumented
130 0 my $tree = shift;
131 0 ▶ return undef unless ref($tree) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $tree eq "HASH" 0 0 0
132 0 return $tree->{status}{code};
133 }
134  
135 # --- Internal use only ---
136  
137 # Blindly flatten a HoH
138 sub flatten
139 0 ▶{
Subroutine flatten: not called CC=4 SCAR=30.0
Pod undocumented
140 0 my $tree = shift;
141 0 ▶ return $tree unless ref($tree) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $tree eq "HASH" 0 0 0
142 0 my %a;
143 0 for( keys %{$tree} )
144 {
145 0 ▶ $a{$_} = $tree->{$_}, next unless ref($tree->{$_}) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $tree->{$_} eq "HASH" 0 0 0
146 0 my %b = flatten($tree->{$_});
147 0 @a{keys %b} = values %b;
148 }
149 0 return %a;
150 }
151  
152 2 1;
153  
154 __END__
« OFX/Parse.pm ↑ Summary OFX/Institution.pm »