/usr/share/perl5/Template/Alloy/Iterator.pm is in libtemplate-alloy-perl 1.020-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | package Template::Alloy::Iterator;
=head1 NAME
Template::Alloy::Iterator - Handle foreach iterations
=cut
use strict;
use warnings;
sub new {
my ($class, $items) = @_;
$items = [] if ! defined $items;
if (ref($items) eq 'HASH') {
$items = [ map { {key => $_, value => $items->{ $_ }} } sort keys %$items ];
} elsif (UNIVERSAL::can($items, 'as_list')) {
$items = $items->as_list;
} elsif (ref($items) ne 'ARRAY') {
$items = [$items];
}
return bless [$items, 0], $class;
}
sub get_first {
my $self = shift;
return (undef, 3) if ! @{ $self->[0] };
return ($self->[0]->[$self->[1] = 0], undef);
}
sub get_next {
my $self = shift;
return (undef, 3) if ++ $self->[1] > $#{ $self->[0] };
return ($self->items->[$self->[1]], undef);
}
sub items { shift->[0] }
sub index { shift->[1] }
sub max { $#{ shift->[0] } }
sub size { shift->max + 1 }
sub count { shift->index + 1 }
sub number { shift->index + 1 }
sub first { (shift->index == 0) || 0 }
sub last { my $self = shift; return ($self->index == $self->max) || 0 }
sub odd { shift->count % 2 ? 1 : 0 }
sub even { shift->count % 2 ? 0 : 1 }
sub parity { shift->count % 2 ? 'odd' : 'even' }
sub prev {
my $self = shift;
return undef if $self->index <= 0;
return $self->items->[$self->index - 1];
}
sub next {
my $self = shift;
return undef if $self->index >= $self->max;
return $self->items->[$self->index + 1];
}
1;
__END__
=head1 DESCRIPTION
Template::Alloy::Iterator provides compatibility with Template::Iterator
and filters that require Template::Iterator.
=head1 TODO
Document all of the methods.
=head1 AUTHOR
Paul Seamons <paul@seamons.com>
=head1 LICENSE
This module may be distributed under the same terms as Perl itself.
=cut
|