| 1 | package QWizard::Storage::File; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use QWizard::Storage::Memory; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 2 | our @ISA = qw(QWizard::Storage::Memory); | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | our $VERSION = '3.15'; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 11 | 2 | my $class = shift; | |||||||||||||||||||||||||||
| 12 | 2 | my %args = @_; | |||||||||||||||||||||||||||
| 13 | 2 | bless \%args, $class; | |||||||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 7 | ▶ | sub set { | ||||||||||||||||||||||||||
|
Subroutine
set: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 17 | 7 | my ($self, $it, $val) = @_; | |||||||||||||||||||||||||||
| 18 | 7 | $self->SUPER::set($it, $val); | |||||||||||||||||||||||||||
| 19 | 7 | $self->save_parms(); | |||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 2 | ▶ | sub set_all { | ||||||||||||||||||||||||||
|
Subroutine
set_all: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 23 | 2 | my ($self, $vals) = @_; | |||||||||||||||||||||||||||
| 24 | 2 | $self->SUPER::set_all($vals); | |||||||||||||||||||||||||||
| 25 | 2 | $self->save_parms(); | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 9 | ▶ | sub save_parms { | ||||||||||||||||||||||||||
|
Subroutine
save_parms: called CC=5 SCAR=16.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 29 | 9 | my $self = shift; | |||||||||||||||||||||||||||
| 30 | 9 | ▶ | return if (!$self); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | 9 | ▶ | return if ($self->{'dontsave'}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 7 | my $vars = $self->get_all(); | |||||||||||||||||||||||||||
| 33 | 7 | ▶ | if ($self->{'file'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 7 | open(OPFILE, ">$self->{'file'}"); | |||||||||||||||||||||||||||
| 35 | 7 | foreach my $var (keys(%$vars)) { | |||||||||||||||||||||||||||
| 36 | 10 | print OPFILE xlat_data_fw($var),"\n"; | |||||||||||||||||||||||||||
| 37 | 10 | print OPFILE xlat_data_fw($vars->{$var}),"\n"; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | 7 | close(OPFILE); | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 1 | ▶ | sub load_data { | ||||||||||||||||||||||||||
|
Subroutine
load_data: called CC=5 SCAR=16.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 44 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 45 | 1 | ▶ | return if (!$self); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 1 | $self->reset(); | |||||||||||||||||||||||||||
| 47 | 1 | $self->{'dontsave'} = 1; | |||||||||||||||||||||||||||
| 48 | 1 | ▶ | if ($self->{'file'} && -f $self->{'file'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"file"} and -f $self->{"file"}
MC/DC0%0/2
$self->{"file"} and -f $self->{"file"}
$self->{"file"}
-f $self->{"file"}
Truth table33%1/3
A and B
A= $self->{"file"}B= -f $self->{"file"}
| |||||||||||||||||||||||||||||
| 49 | 1 | open(IPFILE, "$self->{'file'}"); | |||||||||||||||||||||||||||
| 50 | 1 | ▶ | while (<IPFILE>) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 2 | chomp(); | |||||||||||||||||||||||||||
| 52 | 2 | my $key = xlat_data_rv($_); | |||||||||||||||||||||||||||
| 53 | 2 | $_ = <IPFILE>; | |||||||||||||||||||||||||||
| 54 | 2 | chomp(); | |||||||||||||||||||||||||||
| 55 | 2 | my $val = xlat_data_rv($_); | |||||||||||||||||||||||||||
| 56 | 2 | $self->set($key, $val); | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | 1 | $self->{'dontsave'} = 0; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 20 | ▶ | sub xlat_data_fw { | ||||||||||||||||||||||||||
|
Subroutine
xlat_data_fw: called CC=1 SCAR=0.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 63 | 20 | my $data = shift; | |||||||||||||||||||||||||||
| 64 | 0 | $data =~ s/([^a-zA-Z0-9])/'%' . ord($1) . ";"/eg; | |||||||||||||||||||||||||||
| 65 | 20 | return $data; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 4 | ▶ | sub xlat_data_rv { | ||||||||||||||||||||||||||
|
Subroutine
xlat_data_rv: called CC=1 SCAR=0.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 69 | 4 | my $data = shift; | |||||||||||||||||||||||||||
| 70 | 0 | $data =~ s/\%([0-9]+);/chr($1)/eg; | |||||||||||||||||||||||||||
| 71 | 4 | return $data; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 2 | 1; | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | =pod | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | =head1 NAME | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | QWizard::Storage::File - Stores data in a file | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | my $st = new QWizard::Storage::File(file => '/path/to/some/file'); | ||||||||||||||||||||||||||||
| 85 | $st->set('var', 'value'); | ||||||||||||||||||||||||||||
| 86 | $st->get('var'); | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | # optionally bootstrap from an existing file: | ||||||||||||||||||||||||||||
| 89 | $st->load_data(); | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | Stores data passed to it in a file (and in memory for faster lookups). | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | Generally speaking this should *not* be used except when being copied | ||||||||||||||||||||||||||||
| 96 | to from another faster storage mechanism (like a | ||||||||||||||||||||||||||||
| 97 | QWizard::Storage::Memory object). | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | This module is actually a child class of QWizard::Storage::Memory. | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | Wes Hardaker, hardaker@users.sourceforge.net | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | perl(1) | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | Net-Policy: http://net-policy.sourceforge.net/ | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | =cut | ||||||||||||||||||||||||||||