File Coverage

blib/lib/PPI/Transform/Sequence.pm
Criterion Covered Total %
statement 31 31 100.0
branch 8 8 100.0
condition 1 3 33.3
subroutine 7 7 100.0
pod 3 3 100.0
total 50 52 96.1


line stmt bran cond sub pod time code
1             package PPI::Transform::Sequence;
2              
3 1     1   39013 use strict;
  1         2  
  1         31  
4 1     1   5 use warnings;
  1         2  
  1         44  
5              
6             # ABSTRACT: Tiny binder to combine multiple PPI::Transform objects
7             our $VERSION = 'v0.0.3'; # VERSION
8              
9 1     1   744 use parent qw(PPI::Transform);
  1         290  
  1         5  
10              
11 1     1   170692 use Carp;
  1         3  
  1         309  
12              
13             sub new
14             {
15 5     5 1 3766 my ($self, @args) = @_;
16 5 100       40 croak 'Odd number of arguments are specified' if @args % 2 == 1;
17 4   33     18 my $class = ref($self) || $self;
18 4         10 $self = bless [], $class;
19 4         8 while(@args) {
20 5         19 my ($name, $arg) = splice @args, 0, 2;
21 5 100       22 croak 'The latter of pairs SHOULD be an array reference' if ref($arg) ne 'ARRAY';
22 4         280 eval "require $name";
23 4 100       586 croak "$name can't be loaded: $@" if $@;
24 3 100       41 croak 'The former of pairs SHOULD be a name of PPI::Transform subclass: $name' if ! $name->isa('PPI::Transform');
25 2         12 push @$self, $name->new(@$arg);
26             }
27 1         13 return $self;
28             }
29              
30             sub idx
31             {
32 2     2 1 503 my ($self, $idx) = @_;
33 2         7 return $self->[$idx];
34             }
35              
36             sub document
37             {
38 1     1 1 2807 my ($self, $doc) = @_;
39 1         2 my $count = 0;
40 1         3 foreach my $trans (@$self) {
41 2         610 $count += $trans->document($doc);
42             }
43 1         566 return $count;
44             }
45              
46             1;
47              
48             __END__