Fallback/WholeFile.pm untested

filter: Statementstmt 0.0% 0 / 35 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 64 CC 4 SCAR 22.2
CC
4
Cov
0%
GET
20.0
textToHash
2.0
Include
2.0
CRAP 9.2
1 #!/usr/bin/perl -w
2  
3 package Data::Fallback::WholeFile;
4  
5 use strict;
6  
7 use Data::Fallback;
8 use vars qw(@ISA);
9 @ISA = qw(Data::Fallback);
10 use Carp qw(confess);
11  
12 sub GET {
13 my $self = shift;
14 my $hash = shift;
15 my $return = 0;
16 if( (defined $self->{info}{WholeFile}{data}{$hash->{group}}) && length $self->{info}{WholeFile}{data}{$hash->{group}}) {
17 if( (defined $self->{info}{WholeFile}{data}{$hash->{group}}{$hash->{item}}) &&
18 length $self->{info}{WholeFile}{data}{$hash->{group}}{$hash->{item}}) {
19 $hash->{item} = $self->{info}{WholeFile}{data}{$hash->{group}}{$hash->{item}};
20 $return = 1;
21 }
22 } elsif(-e $hash->{group}) {
23 my $text = Include($hash->{group});
24 $self->{info}{WholeFile}{data}{$hash->{group}} = $text;
25 $hash->{item} = $text;
26 $return = 1;
27 } else {
28 # do nothing
29 }
30  
31 return $return;
32 }
33  
34 sub textToHash {
35 my $text_ref = shift;
36 my %hash = $$text_ref =~ /(.+?)\s+(.+)/g;
37 return \%hash;
38 }
39  
40 sub Include {
41 my $filename = shift;
42 open(FILE, $filename) || confess "couldn't open $filename: $!";
43 my $txt = join("", <FILE>);
44 close(FILE);
45 return $txt;
46  
47 }
48  
49 1;