The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Mojo::DOM::Collection - Element Collection

SYNOPSIS

  use Mojo::DOM::Collection;

DESCRIPTION

Mojo::DOM::Collection is a container for element collections used by Mojo::DOM. Note that this module is EXPERIMENTAL and might change without warning!

METHODS

Mojo::DOM::Collection inherits all methods from Mojo::Base and implements the following new ones.

new

  my $collection = Mojo::DOM::Collection->new([...]);

Construct a new Mojo::DOM::Collection object.

each

  my @elements = $collection->each;
  my $root     = $collection->each(sub { print shift->text });
  my $root     = $collection->each(sub {
    my ($e, $count) = @_;
    print "$count: ", $e->text;
  });

Iterate over whole collection.

to_xml

  my $xml = $collection->to_xml;

Render collection to XML.

until

  my $root = $collection->until(sub { $_->text =~ /x/ && print $_->text });
  my $root = $collection->until(sub {
    my ($e, $count) = @_;
    $e->text =~ /x/ && print "$count: ", $e->text;
  });

Iterate over collection until closure returns true.

while

  my $root = $collection->while(sub {
    print($_->text) && $_->text =~ /x/
  });
  my $root = $collection->while(sub {
    my ($e, $count) = @_;
    print("$count: ", $e->text) && $e->text =~ /x/;
  });

Iterate over collection while closure returns true.

SEE ALSO

Mojolicious, Mojolicious::Guides, http://mojolicio.us.