blib/lib/QWizard/Storage/Base.pm

filter: Statementstmt 73.4% 36 / 49 Branchbran 83.3% 5 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 62.5% 5 / 8 Podpod 0.0% 0 / 7 totaltotal 65.7% 46 / 70 CC 6 SCAR 9.9
CC
6
Cov
75%
set_all
6.0
access
3.0
to_string
2.0
CRAP 2.7
« blib/lib/QWizard/Storage/File.pm ↑ Summary blib/lib/QWizard/API.pm »
1 package QWizard::Storage::Base;
2  
3 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 5 our $VERSION = '3.15';
6  
7 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
8 0 my $class = shift;
9 0 bless {}, $class;
10 }
11  
12 # access is called where the first argument could actually be a
13 # QWizard object, so we drop it.
14 4 ▶sub access {
Subroutine access: called CC=3 SCAR=11.1
Pod undocumented
15 4 my $self = shift;
16 4 my ($it);
17 4 ▶ if (ref($self) =~ /QWizard/) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref($self) =~ /QWizard/) { } 4 0 4
18 4 $it = shift;
19 } else {
20 0 $it = $self;
21 }
22 4 ▶ if ($#_ > -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ > -1) 2 2 4
23 2 $self->set($it, $_[0]);
24 }
25 4 return $self->get($it);
26 }
27  
28 0 ▶sub get_all {
Subroutine get_all: not called CC=1 SCAR=6.9
Pod undocumented
29 0 my $self = shift;
30 0 return $self->{'vars'};
31 }
32  
33 0 ▶sub set_all {
Subroutine set_all: not called CC=2 SCAR=17.9
Pod undocumented
34 0 my $self = shift;
35 0 my $vars = shift;
36 0 $self->reset();
37 0 foreach my $key (%$vars) {
38 0 $self->set($key, $vars->{$key});
39 }
40 }
41  
42 2 ▶sub copy_from {
Subroutine copy_from: called CC=1 SCAR=0.0
Pod undocumented
43 2 my ($self, $from) = @_;
44 2 $self->set_all($from->get_all);
45 }
46  
47 #
48 # converts all known variables into a future parsable string.
49 # warning: not the most efficient encoding. But it should be safe
50 # for use by every transport, assuming '_' and '-' is legal.
51 #
52 2 ▶sub to_string {
Subroutine to_string: called CC=2 SCAR=7.0
Pod undocumented
53 2 my $self = shift;
54 2 my $vars = $self->get_all();
55 2 my $out;
56 2 foreach my $var (keys(%$vars)) {
57 4 my $varstr = $var;
58 0 $varstr =~ s/([^a-zA-Z0-9])/'_' . (ord($1)) . '_'/eg;
59 4 my $valstr = $vars->{$var};
60 0 $valstr =~ s/([^a-zA-Z0-9])/'_' . (ord($1)) . '_'/eg;
61 4 $out .= '_-' . $varstr . '_-' . $valstr;
62 }
63 2 $out =~ s/^_-//;
64 2 return $out;
65 }
66  
67 #
68 # converts an encoded string (see to_string()) into the storage
69 # container (wiping out previous contents)
70 #
71 2 ▶sub from_string {
Subroutine from_string: called CC=2 SCAR=6.9
Pod undocumented
72 2 my $self = shift;
73 2 my $str = shift;
74 2 my %vars;
75  
76 # delete existing data
77 2 $self->reset();
78  
79 # split incoming string into var pieces
80 2 my @vars = split(/_-/,$str);
81  
82 # parse each string
83 2 ▶ for (my $i = 0; $i <= $#vars; $i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#vars) 4 2 6
84 4 my @parts = ($vars[$i], $vars[$i+1]);
85 0 map { s/_(\d+)_/chr($1)/eg; } @parts;
86 4 $self->set(@parts);
87 }
88 2 return $self;
89 }
90  
91 5 1;
92  
93 =pod
94  
95 =head1 NAME
96  
97 QWizard::Storage::Memory - Stores data in CGI variables
98  
99 =head1 SYNOPSIS
100  
101 my $st = new QWizard::Storage::Memory();
102 $st->set('var', 'value');
103 $st->get('var');
104  
105 =head1 DESCRIPTION
106  
107 Stores data passed to it inside of CGI parameters.
108  
109 =head1 AUTHOR
110  
111 Wes Hardaker, hardaker@users.sourceforge.net
112  
113 =head1 SEE ALSO
114  
115 perl(1)
116  
117 Net-Policy: http://net-policy.sourceforge.net/
118  
119 =cut
« blib/lib/QWizard/Storage/File.pm ↑ Summary blib/lib/QWizard/API.pm »