SYNOPSIS

  use Business::EDI;

  my $edi = Business::EDI-new('d09b');      # set the EDI spec version
  my $rtc = $edi->codelist('ResponseTypeCode', $json) or die "Unrecognized code!";
  printf "EDI response type: %s - %s (%s)\n", $rtc->code, $rtc->label, $rtc->value;

  my $msg = Business::EDI::Message->new($ordrsp) or die "Failed Message constructor";
  foreach ($msg->xpath('line_detail/all_LIN') {
      ($_->part(7143) || '') eq 'EN' or next;
      print $_->part(7140)->value, "\n";    # print all the 13-digit (EN) ISBNs
  }

DESCRIPTION

The focus of functionality is to provide object based access to \s-1EDI\s0 messages and subelements. At present, the \s-1EDI\s0 input processed by Business::EDI objects is \s-1JSON\s0 from the edi4r ruby library, and there is no \s-1EDI\s0 output beyond the perl objects themselves.

NAMESPACE

When you \*(C`use Business::EDI;\*(C' the following package namespaces are also loaded:

    Business::EDI::Segment_group
    Business::EDI::Message

That's why the example message constructor in \s-1SYNOPSIS\s0 would succeed without having done \*(C`use Business::EDI::Message;\*(C'

EDI Structure

Everything depends on the spec. That means you have to have declared a spec version before you can create or parse a given chunk of data. The exception is a whole \s-1EDI\s0 message, because each message declares its spec version internally.

\s-1EDI\s0 has a hierachical specification defining data. From top to bottom, it includes:

Communication - containing one or more messages (not yet modeled here)
Message - containing segment groups and segments
Segment Group - containing segments
Segment - containing composites, codelists and data elements
Composite - containing multiple codelists and/or data elements
Codelist - enumerated value from a spec-defined set
Data Element - unenumerated value

This module handles messages and everything below, but not (yet) communications.

CLASS FUNCTIONS

Much more documentation needed here...

\fInew()\fP

Constructor

OBJECT METHODS (General)

\fIvalue()\fP

Get/set accessor for the value of the field.

\fIcode()\fP

The string code designating this node's type. The code is what is what the spec uses to refer to the object's definition. For example, a composite \*(L"C504\*(R", segment \*(L"\s-1RFF\s0\*(R", data element \*(L"7140\*(R", etc.

Don't be confused when dealing with CodeList objects. Calling code() gets you the 4-character code of the CodeList field, \s-1NOT\s0 what that CodeList is currently set to. For that use value().

\fIdesc()\fP

English description of the element.

METHODS (for Traversal)

\fIpart_keys()\fP

This method returns strings that can be fed to part() like:

    foreach ($x->part_keys) { something($x->part($_)) }

This is similar to doing:

    foreach (keys %x) { something($x{$_}) }

In this way an object can be exhaustively, recursively parsed without further knowledge of it.

part($key)

Returns subelement(s) of the object. The key can reference any subobject allowed by the spec. If the subobject is repeatable, then prepending \*(L"all_\*(R" to the key will return an array of all such subobjects. This is the safest and most comprehensive approach. Using part($key) without \*(L"all_\*(R" to retrieve when there is only one $key subobject will succeed. Using part($key) without \*(L"all_\*(R" to retrieve when there are multiple $key subobjects will \s-1FAIL\s0. Since that difference is only dependent on data, you should always use \*(L"all_\*(R" when dealing with a repeatable field (or xpath, see below).

Examples:

my $qty = $detail->part('QTY'); # FAILURE PRONE! my @qtys = $detail->part('all_QTY'); # OK!

xpath($path)

$path can traverse multiple depths in representation via one call. For example:

$message->xpath('all_SG26/all_QTY/6063')

is like this function foo():

sub foo { my @x; for my $sg ($message->part->('all_SG26') { for ($sg->part('all_QTY') { push @x, $->part('6063'); } } return @x; }

The xpath version is much nicer! However this is nowhere near as fully featured as W3C xpath for \s-1XML\s0. This is more like a multple-depth part().

Examples:

    my @obj_1154 = $message->xpath('line_detail/SG31/RFF/C506/1154');

xpath_value($path)

Returns value(s) instead of object(s).

Examples:

    '\s-1ORDRSP\s0' eq $ordrsp->xpath_value('\s-1UNH/S009/0065\s0') or die \*(L"Wrong Message Type!\*(R";

WARNINGS

This code is experimental. \s-1EDI\s0 is a big spec with many revisions.

At the lower levels, all data elements, codelists, composites and segments from the most recent spec (D09B) are present.

RELATED TO Business::EDI…

Business::EDI::Spec edi4r - http://edi4r.rubyforge.org

AUTHOR

Joe Atzberger