File Coverage

blib/lib/Text/TestBase/Block.pm
Criterion Covered Total %
statement 38 45 84.4
branch 6 10 60.0
condition n/a
subroutine 12 14 85.7
pod 4 9 44.4
total 60 78 76.9


line stmt bran cond sub pod time code
1             package Text::TestBase::Block;
2 14     14   72 use strict;
  14         23  
  14         388  
3 14     14   68 use warnings;
  14         25  
  14         322  
4 14     14   981 use utf8;
  14         31  
  14         66  
5             use Class::Accessor::Lite (
6 14         99 ro => [qw/name description/],
7 14     14   402 );
  14         23  
8              
9             sub new {
10 41     41 0 288 my $class = shift;
11 41 50       213 my %args = @_==1 ? %{$_[0]} : @_;
  0         0  
12 41         290 bless {
13             _section_order => [],
14             %args
15             }, $class;
16             }
17              
18             sub has_section {
19 104     104 1 929 my ($self, $key) = @_;
20 104         507 return exists($self->{_value_map}->{$key});
21             }
22              
23             sub get_section {
24 74     74 1 7588 my ($self, $key) = @_;
25 74         147 my $value = $self->{_value_map}->{$key};
26 74 50       178 return undef unless defined $value;
27 74 100       381 return wantarray ? @$value : $value->[0];
28             }
29              
30             sub get_sections {
31 0     0 1 0 my ($self, $key) = @_;
32 0         0 map { $self->{_value_map}->{$_} } $self->get_section_names();
  0         0  
33             }
34              
35             sub get_section_names {
36 27     27 0 48 my ($self, $key) = @_;
37 27         36 @{$self->{_section_order}};
  27         105  
38             }
39              
40             sub get_filter {
41 0     0 1 0 my ($self, $key) = @_;
42 0         0 $self->{_filter_map}->{$key};
43             }
44              
45             sub get_lineno {
46 15     15 0 3893 my $self = shift;
47 15         118 return $self->{_lineno};
48             }
49              
50             sub push_section {
51 63     63 0 141 my ($self, $key, $value, $filters) = @_;
52 63         223 $self->{_filter_map}->{$key} = $filters;
53 63         203 $self->{_value_map}->{$key} = [$value];
54 63         102 push @{$self->{_section_order}}, $key;
  63         384  
55             }
56              
57             sub set_section {
58 38     38 0 81 my ($self, $key, @values) = @_;
59 38         241 $self->{_value_map}->{$key} = [@values];
60             }
61              
62             our $AUTOLOAD;
63             sub AUTOLOAD {
64 18     18   169 $AUTOLOAD =~ s/.*:://;
65 18         44 my $self = shift;
66 18 50       58 return if $AUTOLOAD eq 'DESTROY';
67 18 50       55 unless ($self->has_section($AUTOLOAD)) {
68 0         0 Carp::croak("There is no $AUTOLOAD' section in the block.");
69             }
70 18         53 $self->get_section($AUTOLOAD);
71             }
72              
73             1;
74             __END__