File Coverage

inc/Data/Section/Simple.pm
Criterion Covered Total %
statement 32 32 100.0
branch 5 6 83.3
condition 1 3 33.3
subroutine 6 6 100.0
pod 0 2 0.0
total 44 49 89.8


line stmt bran cond sub pod time code
1             #line 1
2             package Data::Section::Simple;
3 2     2   2078  
  2         3  
  2         80  
4 2     2   62 use strict;
  2         8  
  2         123  
5             use 5.008_001;
6             our $VERSION = '0.02';
7 2     2   11  
  2         59  
  2         885  
8             use base qw(Exporter);
9             our @EXPORT_OK = qw(get_data_section);
10              
11 21     21 0 39 sub new {
12 21   33     138 my($class, $pkg) = @_;
13             bless { package => $pkg || caller }, $class;
14             }
15              
16 42 100   42 0 1002 sub get_data_section {
17             my $self = ref $_[0] ? shift : __PACKAGE__->new(scalar caller);
18 42 100       90  
19 21         65 if (@_) {
20             return $self->get_data_section->{$_[0]};
21 2     2   11 } else {
  2         4  
  2         517  
  21         26  
  21         25  
  21         86  
22 21 50       71 my $d = do { no strict 'refs'; \*{$self->{package}."::DATA"} };
23             return unless defined fileno $d;
24 21         158  
25 21         3873 seek $d, 0, 0;
26 21         2949 my $content = join '', <$d>;
27 21         181 $content =~ s/^.*\n__DATA__\n/\n/s; # for win32
28             $content =~ s/\n__END__\n.*$/\n/s;
29 21         2708  
30 21         49 my @data = split /^@@\s+(.+?)\s*\r?\n/m, $content;
31             shift @data; # trailing whitespaces
32 21         44  
33 21         59 my $all = {};
34 233         319 while (@data) {
35 233         743 my ($name, $content) = splice @data, 0, 2;
36             $all->{$name} = $content;
37             }
38 21         140  
39             return $all;
40             }
41             }
42              
43             1;
44             __END__