File Coverage

blib/lib/Tie/Hash/DataSection.pm
Criterion Covered Total %
statement 63 68 92.6
branch 2 2 100.0
condition 2 3 66.6
subroutine 14 15 93.3
pod n/a
total 81 88 92.0


line stmt bran cond sub pod time code
1 1     1   216714 use warnings;
  1         2  
  1         61  
2 1     1   21 use 5.020;
  1         5  
3 1     1   604 use experimental qw( signatures );
  1         4934  
  1         7  
4 1     1   800 use stable qw( postderef );
  1         505  
  1         7  
5 1     1   649 use true;
  1         10300  
  1         8  
6              
7             package Tie::Hash::DataSection 0.01 {
8              
9             # ABSTRACT: Access __DATA__ section via tied hash
10              
11              
12 1     1   1827 use Data::Section::Pluggable 0.08;
  1         34431  
  1         95  
13 1     1   12 use Ref::Util qw( is_plain_arrayref );
  1         6  
  1         806  
14              
15 3     3   326833 sub TIEHASH ($class, $package=undef, @plugins) {
  3         16  
  3         7  
  3         6  
  3         7  
16 3   66     17 $package //= caller;
17 3         31 my $dsp = Data::Section::Pluggable->new(
18             package => $package,
19             );
20 3         721 foreach my $plugin (@plugins) {
21 2 100       10 if(is_plain_arrayref $plugin) {
22 1         4 my($name, @args) = @$plugin;
23 1         7 $dsp->add_plugin($name => @args);
24             } else {
25 1         7 $dsp->add_plugin($plugin);
26             }
27             }
28 3         17257 return bless [$dsp], $class;
29             }
30              
31 4     4   1009 sub FETCH ($self, $key) {
  4         8  
  4         9  
  4         6  
32 4         22 return $self->[0]->get_data_section($key);
33             }
34              
35 2     2   2118 sub EXISTS ($self, $key) {
  2         5  
  2         5  
  2         4  
36 2         9 exists $self->[0]->get_data_section->{$key};
37             }
38              
39 1     1   601 sub FIRSTKEY ($self) {
  1         3  
  1         2  
40 1         6 $self->[1] = [keys $self->[0]->get_data_section->%*];
41 1         226 return $self->NEXTKEY;
42             }
43              
44 3     3   6 sub NEXTKEY ($self, $=undef) {
  3         5  
  3         7  
  3         4  
45 3         20 return shift $self->[1]->@*;
46             }
47              
48 1     1   899 sub STORE ($self, $, $) {
  1         3  
  1         2  
49 1         9 require Carp;
50 1         252 Carp::croak("hash is read-only");
51             }
52              
53 1     1   762 sub DELETE ($self, $) {
  1         4  
  1         2  
54 1         7 require Carp;
55 1         145 Carp::croak("hash is read-only");
56             }
57              
58 0     0     sub CLEAR ($self) {
  0            
  0            
59 0           require Carp;
60 0           Carp::croak("hash is read-only");
61             }
62             }
63              
64             __END__