File: CollectionItem.pm

package info (click to toggle)
libapache-asp-perl 2.63-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 4,120 kB
  • sloc: perl: 6,044; php: 409; sh: 62; lisp: 22; makefile: 10
file content (30 lines) | stat: -rw-r--r-- 524 bytes parent folder | download | duplicates (7)
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;