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::Tree; |
7
|
4
|
|
|
4
|
|
13559
|
use strict; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
4053
|
|
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::Tree ':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
|
|
|
|
|
|
|
#use X12::Parser::Tree; |
30
|
|
|
|
|
|
|
#This class holds the loop structure of the X12 transaction. |
31
|
|
|
|
|
|
|
#The class is populated by X12::Parser::Cf and loaded from the *.cf file. |
32
|
|
|
|
|
|
|
#constructor. |
33
|
|
|
|
|
|
|
sub new { |
34
|
139
|
|
|
139
|
0
|
698
|
my $self = { |
35
|
|
|
|
|
|
|
_PARENT => undef, |
36
|
|
|
|
|
|
|
_CHILDREN => undef, |
37
|
|
|
|
|
|
|
_NAME => undef, |
38
|
|
|
|
|
|
|
_SEG => undef, |
39
|
|
|
|
|
|
|
_SEG_QUAL => undef, |
40
|
|
|
|
|
|
|
_SEG_QUAL_POS => undef, |
41
|
|
|
|
|
|
|
_DEPTH => 0, |
42
|
|
|
|
|
|
|
}; |
43
|
139
|
|
|
|
|
327
|
return bless $self; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub set_name { |
47
|
139
|
|
|
139
|
0
|
219
|
my ( $self, $name ) = @_; |
48
|
139
|
|
|
|
|
350
|
$self->{_NAME} = $name; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub get_name { |
52
|
37
|
|
|
37
|
0
|
166
|
my $self = shift; |
53
|
37
|
|
|
|
|
113
|
return $self->{_NAME}; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub is_root { |
57
|
1
|
|
|
1
|
0
|
532
|
my $self = shift; |
58
|
1
|
50
|
|
|
|
8
|
return ( defined $self->{_PARENT} ) ? 0 : 1; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub set_parent { |
62
|
132
|
|
|
132
|
0
|
184
|
my ( $self, $parent ) = @_; |
63
|
132
|
|
|
|
|
284
|
$self->{_PARENT} = $parent; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub get_parent { |
67
|
100
|
|
|
100
|
0
|
495
|
my $self = shift; |
68
|
100
|
|
|
|
|
172
|
return $self->{_PARENT}; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub has_children { |
72
|
2
|
|
|
2
|
0
|
372
|
my $self = shift; |
73
|
2
|
50
|
|
|
|
10
|
return ( defined $self->{_CHILDREN} ) ? 1 : 0; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub get_child { |
77
|
417
|
|
|
417
|
0
|
1363
|
my ( $self, $index ) = @_; |
78
|
417
|
|
|
|
|
815
|
return $self->{_CHILDREN}->[$index]; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub get_children { |
82
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
83
|
0
|
|
|
|
|
0
|
return $self->{_CHILDREN}; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub get_child_count { |
87
|
646
|
|
|
646
|
0
|
1139
|
my $self = shift; |
88
|
646
|
100
|
|
|
|
1172
|
if ( defined $self->{_CHILDREN} ) { |
89
|
581
|
|
|
|
|
579
|
return scalar @{ $self->{_CHILDREN} }; |
|
581
|
|
|
|
|
1702
|
|
90
|
|
|
|
|
|
|
} |
91
|
65
|
|
|
|
|
187
|
return 0; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub add_child { |
95
|
132
|
|
|
132
|
0
|
167
|
my ( $self, $child ) = @_; |
96
|
132
|
100
|
|
|
|
205
|
if ( $self->get_child_count() ) { |
97
|
104
|
|
|
|
|
170
|
$child->{_DEPTH} = $self->{_DEPTH} + 1; |
98
|
104
|
|
|
|
|
101
|
push( @{ $self->{_CHILDREN} }, $child ); |
|
104
|
|
|
|
|
298
|
|
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
else { |
101
|
28
|
|
|
|
|
55
|
$child->{_DEPTH} = $self->{_DEPTH} + 1; |
102
|
28
|
|
|
|
|
27
|
my @children; |
103
|
28
|
|
|
|
|
37
|
$self->{_CHILDREN} = \@children; |
104
|
28
|
|
|
|
|
34
|
push( @{ $self->{_CHILDREN} }, $child ); |
|
28
|
|
|
|
|
109
|
|
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub set_loop_start_parm { |
109
|
132
|
|
|
132
|
0
|
479
|
my ( $self, @args ) = @_; |
110
|
132
|
|
|
|
|
213
|
$self->{_SEG} = $args[0]; |
111
|
132
|
100
|
|
|
|
301
|
if ( $args[1] eq '' ) { $self->{_SEG_QUAL_POS} = undef; } |
|
59
|
|
|
|
|
184
|
|
112
|
|
|
|
|
|
|
else { |
113
|
73
|
|
|
|
|
118
|
$self->{_SEG_QUAL_POS} = $args[1]; |
114
|
73
|
|
|
|
|
189
|
my @array = split( /,/, $args[2] ); |
115
|
73
|
|
|
|
|
266
|
$self->{_SEG_QUAL} = \@array; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub is_loop_start { |
120
|
414
|
|
|
414
|
0
|
1716
|
my ( $self, $elements ) = @_; |
121
|
414
|
100
|
|
|
|
439
|
if ( $self->{_SEG} eq @{$elements}[0] ) { |
|
414
|
|
|
|
|
781
|
|
122
|
33
|
100
|
|
|
|
57
|
if ( defined( $self->{_SEG_QUAL_POS} ) ) { |
123
|
|
|
|
|
|
|
return |
124
|
20
|
|
|
|
|
23
|
scalar grep { /@{$elements}[$self->{_SEG_QUAL_POS}]/ } |
|
20
|
|
|
|
|
247
|
|
|
16
|
|
|
|
|
29
|
|
125
|
16
|
|
|
|
|
18
|
@{ $self->{_SEG_QUAL} }; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
else { |
128
|
17
|
|
|
|
|
49
|
return 1; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
} |
131
|
381
|
|
|
|
|
1463
|
return 0; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
sub get_depth { |
135
|
17
|
|
|
17
|
0
|
48
|
my $self = shift; |
136
|
17
|
|
|
|
|
86
|
return $self->{_DEPTH}; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub print_tree { |
140
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
141
|
0
|
|
|
|
|
|
my $node = shift; |
142
|
0
|
0
|
|
|
|
|
if ( !defined $node ) { $node = $self; } |
|
0
|
|
|
|
|
|
|
143
|
0
|
|
|
|
|
|
my $pad = ' ' x $node->get_depth(); |
144
|
0
|
|
|
|
|
|
print $pad . $node->get_name . "\n"; |
145
|
0
|
|
|
|
|
|
for ( my $i = 0 ; $i < $node->get_child_count() ; $i++ ) { |
146
|
0
|
|
|
|
|
|
$self->print_tree( $node->get_child($i) ); |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
1; |
150
|
|
|
|
|
|
|
__END__ |