EDI: The get_li_attr_jedi() helper for A/T templates now takes a limit arg collab/senator/edi-limits
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Tue, 18 Sep 2012 21:28:02 +0000 (17:28 -0400)
committerLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Tue, 18 Sep 2012 21:28:02 +0000 (17:28 -0400)
Some vendors seem to use EDI software that doesn't accept long values in
segments.  This allows you to call the get_li_attr_jedi() helper in your
A/T templates with an argument that limits the (pre-jsonification)
length of the returned string.

Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Reactor.pm

index a56a2cd..f7e3b8e 100644 (file)
@@ -22,16 +22,27 @@ sub NOOP_False { return  0 }
 # here, we can't really reuse it within that structure.
 sub get_li_attr {
     my $name = shift or return;     # the first arg is always the name
-    my ($type, $attr) = (scalar(@_) == 1) ? (undef, $_[0]) : @_;
+    my ($type, $attr, $limit); 
+    if (scalar(@_) == 1) {
+        ($type, $attr, $limit) = (undef, @_);
+    } else {
+        ($type, $attr, $limit) = @_;
+    }
+
     # if the next is the last, it's the attributes, otherwise type
     # use Data::Dumper; $logger->warn("get_li_attr: " . Dumper($attr));
     ($name and @$attr) or return;
+
     my $length;
     $name =~ s/^(\D+)_(\d+)$/$1/ and $length = $2;
     foreach (@$attr) {
         $_->attr_name eq $name or next;
         next if $length and $length != length($_->attr_value);
-        return $_->attr_value if (! $type) or $type eq $_->attr_type;
+
+        my $value = $_->attr_value;
+        $value = substr($value, 0, $limit) if $limit;
+
+        return $value if (! $type) or $type eq $_->attr_type;
     }
     return;
 }