OFX/Tree.pm

filter: Statementstmt 31.4% 11 / 35 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 42.8% 3 / 7 Podpod 100% 1 / 1 totaltotal 31.9% 15 / 47 CC 3 SCAR 16.1
CC
3
Cov
28%
__ANON__
12.0
parse
2.0
__ANON__
2.0
CRAP 5.0
« OFX/Response.pm ↑ Summary OFX/Account.pm »
1 # Filename: Teee.pm
2 # Parse 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: Tree.pm,v 1.2 2008/03/04 04:22:27 bfoz Exp $
10  
11 package Finance::OFX::Tree;
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 HTML::Parser;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 sub parse
21 0 ▶{
Subroutine parse: not called CC=1 SCAR=6.9
Pod documented
22 0 my $source = shift;
23  
24 0 my @tree;
25 my @stack;
26 0 unshift @stack, \@tree;
27  
28 my $p = HTML::Parser->new(
29 start_h => [sub
30 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
31 0 my $data = shift;
32  
33 0 my @content = ();
34 0 push @{$stack[0]}, {name => $data, content => \@content};
35 0 unshift @stack, \@content;
36 }, 'tagname'],
37 end_h => [sub
38 0 ▶ { # An end event unwinds the stack by one level
Subroutine __ANON__: not called CC=1 SCAR=6.9
39 0 shift(@stack);
40 }, ''],
41 text_h => [sub
42 0 ▶ {
Subroutine __ANON__: not called CC=3 SCAR=24.8
43 0 my $data = shift;
44 0 $data =~ s/^\s*//; # Strip leading whitespace
45 0 $data =~ s/\s*$//; # Strip trailing whitespace
46 0 ▶ return unless length $data; # Ignore empty strings
Branch: 1 branch
BranchTrueFalseTotal
unless length $data 0 0 0
47 0 ▶ if( scalar(@{$stack[0]}) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @{$stack[0];}) 0 0 0
48 {
49 0 print STDERR "Naked text\n";
50 0 return;
51 }
52 0 shift @stack; # Unwind the vestigal array reference
53 0 @{$stack[0]}[-1]->{content} = $data;
54 0 }, 'dtext' ]);
55 0 $p->unbroken_text(1); # Want element contents in single blocks to facilitate parsing
56 0 $p->parse($source);
57 0 \@tree;
58 }
59  
60 2 1;
61  
62 __END__
« OFX/Response.pm ↑ Summary OFX/Account.pm »