1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
package Apache::ASP::CollectionItem;
use strict;
# for support of $Request->QueryString->('foo')->Item() syntax
sub new {
my($package, $rv) = @_;
my @items = @$rv;
bless {
'Item' => $items[0],
'Items' => \@items,
'Count' => defined $items[0] ? scalar(@items) : 0,
}, $package;
}
sub Count { shift->{Count} };
sub Item {
my($self, $index) = @_;
my $items = $self->{Items};
if(defined $index) {
$items->[$index-1];
} else {
wantarray ? @$items : $items->[0];
}
}
1;
|