line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Filename: Teee.pm |
2
|
|
|
|
|
|
|
# Parse the Open Financial Exchange format |
3
|
|
|
|
|
|
|
# http://www.ofx.net/ |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# Created January 30, 2008 Brandon Fosdick |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
# Copyright 2008 Brandon Fosdick (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
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
14
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '2'; |
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
1
|
|
1685
|
use HTML::Parser; |
|
1
|
|
|
|
|
9535
|
|
|
1
|
|
|
|
|
602
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub parse |
21
|
|
|
|
|
|
|
{ |
22
|
0
|
|
|
0
|
1
|
|
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
|
|
|
|
|
|
|
{ |
31
|
0
|
|
|
0
|
|
|
my $data = shift; |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
my @content = (); |
34
|
0
|
|
|
|
|
|
push @{$stack[0]}, {name => $data, content => \@content}; |
|
0
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
unshift @stack, \@content; |
36
|
|
|
|
|
|
|
}, 'tagname'], |
37
|
|
|
|
|
|
|
end_h => [sub |
38
|
|
|
|
|
|
|
{ # An end event unwinds the stack by one level |
39
|
0
|
|
|
0
|
|
|
shift(@stack); |
40
|
|
|
|
|
|
|
}, ''], |
41
|
|
|
|
|
|
|
text_h => [sub |
42
|
|
|
|
|
|
|
{ |
43
|
0
|
|
|
0
|
|
|
my $data = shift; |
44
|
0
|
|
|
|
|
|
$data =~ s/^\s*//; # Strip leading whitespace |
45
|
0
|
|
|
|
|
|
$data =~ s/\s*$//; # Strip trailing whitespace |
46
|
0
|
0
|
|
|
|
|
return unless length $data; # Ignore empty strings |
47
|
0
|
0
|
|
|
|
|
if( scalar(@{$stack[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; |
|
0
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
1; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
__END__ |