| 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; |