File Coverage

blib/lib/Sub/Chain/Named.pm
Criterion Covered Total %
statement 29 30 96.6
branch 4 6 66.6
condition 2 2 100.0
subroutine 9 9 100.0
pod 3 3 100.0
total 47 50 94.0


line stmt bran cond sub pod time code
1             # vim: set ts=2 sts=2 sw=2 expandtab smarttab:
2             #
3             # This file is part of Sub-Chain
4             #
5             # This software is copyright (c) 2010 by Randy Stauner.
6             #
7             # This is free software; you can redistribute it and/or modify it under
8             # the same terms as the Perl 5 programming language system itself.
9             #
10 1     1   1017 use strict;
  1         3  
  1         47  
11 1     1   7 use warnings;
  1         1  
  1         58  
12              
13             package Sub::Chain::Named;
14             BEGIN {
15 1     1   23 $Sub::Chain::Named::VERSION = '0.012';
16             }
17             BEGIN {
18 1     1   21 $Sub::Chain::Named::AUTHORITY = 'cpan:RWSTAUNER';
19             }
20             # ABSTRACT: subclass of Sub::Chain with named subs
21              
22 1     1   6 use Carp qw(croak);
  1         2  
  1         171  
23 1     1   538 use Sub::Chain;
  1         3  
  1         236  
24             our @ISA = qw(Sub::Chain);
25              
26              
27             sub new {
28 2     2 1 970 my $class = shift;
29 2 50       9 my %opts = ref $_[0] ? %{$_[0]} : @_;
  0         0  
30 2         5 my $subs = delete $opts{subs};
31              
32 2         10 my $self = $class->SUPER::new(%opts);
33 2   100     9 $self->{named} = $subs || {};
34              
35 2         5 return $self;
36             }
37              
38              
39             sub append {
40 4     4 1 970 my ($self, $name, @append) = @_;
41 4 50       18 my $sub = $self->{named}{$name}
42             or croak("No sub defined for name: $name");
43 4         44 $self->SUPER::append($sub, @append);
44             }
45              
46              
47             sub name_subs {
48 3     3 1 1917 my ($self) = shift;
49 3 100       11 my %subs = ref $_[0] ? %{$_[0]} : @_;
  1         4  
50              
51             # TODO: warn if already exists?
52 3         6 @{ $self->{named} }{keys %subs} = values %subs;
  3         10  
53              
54             # chainable
55 3         6 return $self;
56             }
57              
58             1;
59              
60              
61             __END__