line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright 2009 by Prasad Balan |
2
|
|
|
|
|
|
|
# All rights reserved. |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# This library is free software; you can redistribute it and/or modify |
5
|
|
|
|
|
|
|
# it under the same terms as Perl itself. |
6
|
|
|
|
|
|
|
package X12::Parser::Cf; |
7
|
3
|
|
|
3
|
|
7847
|
use strict; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
318
|
|
8
|
|
|
|
|
|
|
require Exporter; |
9
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export |
12
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead. |
13
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants. |
14
|
|
|
|
|
|
|
# This allows declaration use X12::Parser::Cf ':all'; |
15
|
|
|
|
|
|
|
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK |
16
|
|
|
|
|
|
|
# will save memory. |
17
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( |
18
|
|
|
|
|
|
|
'all' => [ |
19
|
|
|
|
|
|
|
qw( |
20
|
|
|
|
|
|
|
) |
21
|
|
|
|
|
|
|
] |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
24
|
|
|
|
|
|
|
our @EXPORT = qw( |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
our $VERSION = '0.80'; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# Preloaded methods go here. |
29
|
3
|
|
|
3
|
|
481
|
use X12::Parser::Tree; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
1774
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub new { |
32
|
6
|
|
|
6
|
0
|
81
|
my $self = { _LINES => undef, }; |
33
|
6
|
|
|
|
|
19
|
return bless $self; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub load { |
37
|
6
|
|
|
6
|
0
|
18
|
my $self = shift; |
38
|
6
|
|
|
|
|
24
|
my %params = @_; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
#open the config file and read it into array |
41
|
6
|
50
|
|
|
|
255
|
open( FILE, $params{file} ) |
42
|
|
|
|
|
|
|
|| die "error: cannot open cf file $params{file}\n"; |
43
|
6
|
|
|
|
|
535
|
@{ $self->{_LINES} } = ; |
|
6
|
|
|
|
|
132
|
|
44
|
6
|
|
|
|
|
31
|
chomp( @{ $self->{_LINES} } ); |
|
6
|
|
|
|
|
57
|
|
45
|
6
|
|
|
|
|
54
|
close(FILE); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
#create the root tree object |
48
|
6
|
|
|
|
|
40
|
my $root = X12::Parser::Tree->new(); |
49
|
6
|
|
|
|
|
26
|
$root->set_name("X12"); |
50
|
6
|
|
|
|
|
20
|
my $pos = $self->_get_loop_pos("LOOPS"); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
#parse the LOOPS section of the config file |
53
|
6
|
|
|
|
|
13
|
for ( my $i = $pos ; $i < scalar @{ $self->{_LINES} } ; $i++ ) { |
|
62
|
|
|
|
|
134
|
|
54
|
62
|
100
|
|
|
|
165
|
if ( $self->{_LINES}->[$i] !~ /^[a-zA-Z0-9#]/ ) { |
55
|
6
|
|
|
|
|
10
|
last; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
else { |
58
|
56
|
|
|
|
|
122
|
$self->_parse_loop( $root, $self->{_LINES}->[$i] ); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
6
|
|
|
|
|
29
|
return $root; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
#get the position of a loop section e.g. [2300] |
65
|
|
|
|
|
|
|
sub _get_loop_pos { |
66
|
131
|
|
|
131
|
|
178
|
my ( $self, $loop ) = @_; |
67
|
131
|
|
|
|
|
184
|
for ( my $i = 0 ; $i < @{ $self->{_LINES} } ; $i++ ) { |
|
19622
|
|
|
|
|
48377
|
|
68
|
19622
|
100
|
|
|
|
67441
|
if ( $self->{_LINES}->[$i] =~ /^\[$loop\]/ ) { |
69
|
131
|
|
|
|
|
327
|
return $i + 1; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
0
|
|
|
|
|
0
|
return undef; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub _parse_loop { |
76
|
125
|
|
|
125
|
|
176
|
my ( $self, $node, $loop ) = @_; |
77
|
125
|
|
|
|
|
408
|
my $pos = $self->_get_loop_pos($loop); |
78
|
125
|
|
|
|
|
155
|
my $end = undef; |
79
|
125
|
|
|
|
|
387
|
my $child = X12::Parser::Tree->new(); |
80
|
125
|
|
|
|
|
293
|
$child->set_name($loop); |
81
|
125
|
50
|
|
|
|
426
|
if ( $self->{_LINES}->[$pos] =~ /^segment=/ ) { |
82
|
125
|
|
|
|
|
283
|
$end = substr $self->{_LINES}->[$pos], 8; |
83
|
|
|
|
|
|
|
} |
84
|
125
|
|
|
|
|
619
|
$child->set_loop_start_parm( split( /:/, $end ) ); |
85
|
125
|
|
|
|
|
378
|
$child->set_parent($node); |
86
|
125
|
|
|
|
|
352
|
$node->add_child($child); |
87
|
125
|
|
|
|
|
196
|
for ( my $i = $pos ; $i < scalar( @{ $self->{_LINES} } ) ; $i++ ) { |
|
868
|
|
|
|
|
2525
|
|
88
|
868
|
100
|
|
|
|
2894
|
if ( $self->{_LINES}->[$i] =~ /^segment=/ ) { |
89
|
674
|
|
|
|
|
958
|
next; |
90
|
|
|
|
|
|
|
} |
91
|
194
|
100
|
|
|
|
434
|
if ( $self->{_LINES}->[$i] =~ /^loop=/ ) { |
92
|
69
|
|
|
|
|
312
|
$end = substr $self->{_LINES}->[$i], 5; |
93
|
69
|
|
|
|
|
162
|
$self->_parse_loop( $child, $end ); |
94
|
|
|
|
|
|
|
} |
95
|
194
|
100
|
|
|
|
724
|
if ( $self->{_LINES}->[$i] !~ /^[a-zA-Z0-9#]/ ) { |
96
|
125
|
|
|
|
|
250
|
last; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
1; |
101
|
|
|
|
|
|
|
__END__ |