# 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;
}