More/Source.pm untested

filter: Statementstmt 0.0% 0 / 44 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 67 CC 4 SCAR 17.0
CC
4
Cov
0%
find
12.0
new
6.0
push
2.0
CRAP 5.5
1 package Text::Lorem::More::Source;
2  
3 use warnings;
4 use strict;
5  
6 use constant DEFAULT_PRIORITY => 2 ** 6;
7 use Carp;
8  
9 sub new {
10 my $self = bless {}, shift;
11 my $generator = shift;
12 my $priority = shift;
13 $self->{source} = [];
14  
15 $self->push($generator, $priority) if defined $generator;
16  
17 return $self;
18 }
19  
20 sub push {
21 my $self = shift;
22 my $generator = shift;
23 my $priority = shift || DEFAULT_PRIORITY;
24 $self->{source} = [ sort { $a->[1] cmp $b->[1] } @{ $self->{source} }, [ $generator, $priority ] ];
25 }
26  
27 sub copy {
28 my $self = shift;
29 my $copy = new __PACKAGE__;
30 for (@{ $self->{source} }) {
31 $copy->push({ %{ $_->[0] } }, $->[1]);
32 }
33 return $copy;
34 }
35  
36 sub find {
37 my $self = shift;
38 my $name = shift;
39  
40 for (@{ $self->{source} }) {
41 next unless defined (my $generatelet = $_->[0]->{$name});
42 return $generatelet if ref $generatelet;
43 return $self->find($generatelet);
44 }
45  
46 croak "couldn't find generatelet for \"$name\"";
47 }
48  
49 1;