1 package Koha
::Edifact
::Segment
;
3 # Copyright 2014,2016 PTFS-Europe Ltd
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
25 my ( $class, $parm_ref ) = @_;
27 if ( $parm_ref->{seg_string
} ) {
28 $self = _parse_seg
( $parm_ref->{seg_string
} );
40 # return specified element may be data or an array ref if components
42 my ( $self, $element_number, $component_number ) = @_;
43 if ( $element_number < @
{ $self->{elem_arr
} } ) {
45 my $e = $self->{elem_arr
}->[$element_number];
46 if ( defined $component_number ) {
47 if ( ref $e eq 'ARRAY' ) {
48 if ( $component_number < @
{$e} ) {
49 return $e->[$component_number];
52 elsif ( $component_number == 0 ) {
54 # a string could be an element with a single component
63 return; #element undefined ( out of range
67 my ( $self, @params ) = @_;
69 return $self->elem(@params);
75 my $string = $self->{tag
};
76 foreach my $e ( @
{ $self->{elem_arr
} } ) {
78 if ( ref $e eq 'ARRAY' ) {
79 $string .= join q{:}, @
{$e};
89 # parse a string into fields
93 tag
=> substr( $s, 0, 3 ),
94 elem_arr
=> _get_elements
( substr( $s, 3 ) ),
106 $seg =~ s/^[+]//; # dont start with a dummy element`
107 my @elem_array = map { _components
($_) } split /(?<![?])[+]/, $seg;
114 my @c = split /(?<![?])[:]/, $element;
115 if ( @c == 1 ) { # single element return a string
116 return de_escape
( $c[0] );
118 @c = map { de_escape
($_) } @c;
125 # remove escaped characters from the component string
126 $string =~ s/[?]([:?+'])/$1/g;
134 Koha::Edifact::Segment - Class foe Edifact Segments
138 Used by Koha::Edifact to represent segments in a parsed Edifact message
145 my $s = Koha::Edifact::Segment->new( { seg_string => $raw });
147 passed a string representation of the segment, parses it
148 and retums a Segment object
152 returns the three character segment tag
156 $data = $s->elem($element_number, $component_number)
157 return the contents of a specified element and if specified
158 component of that element
162 syntactic sugar this wraps the rlem method in a fuller name
166 returns a string representation of the segment
170 passed a string representation of a segment returns a hash ref with
171 separate tag and data elements
175 passed the data portion of a segment, splits it into elements, passing each to
176 components to further parse them. Returns a reference to an array of
181 Passed a string element splits it into components and returns a reference
182 to an array of components, if only one component is present that is returned
184 quote characters are removed from the components
188 Removes Edifact escapes from the passed string and returns the modified
194 Colin Campbell <colin.campbell@ptfs-europe.com>
199 Copyright 2014,2016, PTFS-Europe Ltd
200 This program is free software, You may redistribute it under
201 under the terms of the GNU General Public License