The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Transport::AU::PTV::Collection

VERSION

version 0.01

NAME

Transport::AU::PTV::Collecton - parent class for Transport::AU::PTV collection objects.

Synopsis

Description

Methods

new

map

    my @names = $collection->map(sub { $_->name });

Iterates over each object in the collection and runs subroutine. Each object is passed in to the sub as $_.

Returns an array of the return value of each subroutine. The number of array elements will always equal the number of objects in the collection.

grep

    my @matches = $collection->grep(sub { $_->name =~ s{A...b}xms };

Iterates over each of the objects and returns a Transport::AU::PTV::Collection object of all the objects for which the subroutine passed to grep returned 'true'.

first

    my $match = $collection->first(sub { $_->name eq 'A_Name' });

Like grep, but returns the first object for which the subroutine returns true.

find

    my $value = $collection->find({ name => 'value' });

Syntactic sugar for $collection-first(sub { $_->name eq 'value' });>. The key of the hashref is the method to run on the object. The value of the hashref is the expected return from that method. Equality is determined using 'eq', thus the return values are stringified before testing.

count

Returns the number of objects in the collection.

as_array

    for my $object ($collection->as_array) { ... }

Returns the collection as an array of objects. No copying occurs, so the objects are references to the same objects within the collection.

AUTHOR

Greg Foletta <greg@foletta.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2018 by Greg Foletta.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.