| 1 | # -*- perl -*- | ||||||||||||||||||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||||||||||||||||||
| 3 | # HTML::EP - A Perl based HTML extension. | ||||||||||||||||||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||||||||||||||||||
| 6 | # Copyright (C) 1998 Jochen Wiedmann | ||||||||||||||||||||||||||||||||||||||||||||
| 7 | # Am Eisteich 9 | ||||||||||||||||||||||||||||||||||||||||||||
| 8 | # 72555 Metzingen | ||||||||||||||||||||||||||||||||||||||||||||
| 9 | # Germany | ||||||||||||||||||||||||||||||||||||||||||||
| 10 | # | ||||||||||||||||||||||||||||||||||||||||||||
| 11 | # Phone: +49 7123 14887 | ||||||||||||||||||||||||||||||||||||||||||||
| 12 | # Email: joe@ispsoft.de | ||||||||||||||||||||||||||||||||||||||||||||
| 13 | # | ||||||||||||||||||||||||||||||||||||||||||||
| 14 | # All rights reserved. | ||||||||||||||||||||||||||||||||||||||||||||
| 15 | # | ||||||||||||||||||||||||||||||||||||||||||||
| 16 | # You may distribute this module under the terms of either | ||||||||||||||||||||||||||||||||||||||||||||
| 17 | # the GNU General Public License or the Artistic License, as | ||||||||||||||||||||||||||||||||||||||||||||
| 18 | # specified in the Perl README file. | ||||||||||||||||||||||||||||||||||||||||||||
| 19 | # | ||||||||||||||||||||||||||||||||||||||||||||
| 20 | ############################################################################ | ||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||
| 22 | 2 | require 5.004; | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||
| 25 | 2 | require HTML::EP::Session; | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 2 | require HTML::EP::Locale; | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 2 | require Storable; | |||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||
| 30 | package HTML::EP::Shop; | ||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||
| 32 | 2 | $HTML::EP::Shop::VERSION = '0.1001'; | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 2 | @HTML::EP::Shop::ISA = qw(HTML::EP::Session HTML::EP::Locale HTML::EP); | |||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | sub init { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | if (!$self->{'_ep_language'}) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | $self->HTML::EP::Session::init(@_); | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | $self->HTML::EP::Locale::init(@_); | |||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | sub _ep_shop_upload { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ep_shop_upload: not called CC=22 SCAR=62.3
| |||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | my $self = shift; my $attr = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | my $cgi = $self->{'cgi'}; | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | my $debug = $self->{'debug'}; | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | my $cgivar = $attr->{'cgivar'} || die "Missing CGI variable"; | ||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$attr->{'cgivar'} || die('Missing CGI variable')
MC/DC0%0/1
$attr->{'cgivar'} || die('Missing CGI variable')
$attr->{'cgivar'}
Truth table0%0/2
A
A= $attr->{'cgivar'}
| |||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | my $dsn = $attr->{'dsn'} || "DBI:CSV:"; | ||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$attr->{'dsn'} || 'DBI:CSV:'
MC/DC0%0/1
$attr->{'dsn'} || 'DBI:CSV:'
$attr->{'dsn'}
Truth table0%0/2
A
A= $attr->{'dsn'}
| |||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | if ($debug) { $self->print("Making secondary DSN: $dsn\n") } | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | my $dbhf = DBI->connect($dsn, undef, undef, | |||||||||||||||||||||||||||||||||||||||||||
| 54 | {'RaiseError' => 1, 'Warn' => 0, | ||||||||||||||||||||||||||||||||||||||||||||
| 55 | 'PrintError' => 0}); | ||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | my $csv = Text::CSV_XS->new | ||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/9
$cgi->param('sep') || ';'
$cgi->param('escape') || '"'
$cgi->param('quote') || $cgi->param('escape') || '"'
$cgi->param("quote") or $cgi->param("escape")
MC/DC0%0/1
$cgi->param('sep') || ';'
$cgi->param('sep')
MC/DC0%0/1
$cgi->param('escape') || '"'
$cgi->param('escape')
MC/DC0%0/2
$cgi->param('quote') || $cgi->param('escape') || '"'
$cgi->param("quote")
$cgi->param("escape")
Truth table0%0/2
A
A= $cgi->param('sep')
Truth table0%0/2
A
A= $cgi->param('escape')
Truth table0%0/3
A or B
A= $cgi->param("quote")B= $cgi->param("escape")
| |||||||||||||||||||||||||||||||||||||||||||||
| 57 | ({ 'binary' => 1, 'eol' => "\r\n", | ||||||||||||||||||||||||||||||||||||||||||||
| 58 | 'sep_char' => $cgi->param('sep') || ';', | ||||||||||||||||||||||||||||||||||||||||||||
| 59 | 'quote_char' => $cgi->param('escape') || '"', | ||||||||||||||||||||||||||||||||||||||||||||
| 60 | 'escape_char' => $cgi->param('quote') || $cgi->param('escape') | ||||||||||||||||||||||||||||||||||||||||||||
| 61 | || '"' | ||||||||||||||||||||||||||||||||||||||||||||
| 62 | }); | ||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | $dbhf->{'csv_csv'} = $csv; | |||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | my $table = $attr->{'table'} || die "Missing table name"; | ||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$attr->{'table'} || die('Missing table name')
MC/DC0%0/1
$attr->{'table'} || die('Missing table name')
$attr->{'table'}
Truth table0%0/2
A
A= $attr->{'table'}
| |||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | my $fileName = $cgi->param($cgivar); | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | my $tmpFile = $cgi->tmpFileName($fileName) || die "Missing file"; | ||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$cgi->tmpFileName($fileName) || die('Missing file')
MC/DC0%0/1
$cgi->tmpFileName($fileName) || die('Missing file')
$cgi->tmpFileName($fileName)
Truth table0%0/2
A
A= $cgi->tmpFileName($fileName)
| |||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | if ($debug) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | $self->printf("Reading table %s, file name %s, tmpfile %s.\n", | |||||||||||||||||||||||||||||||||||||||||||
| 70 | $table, $fileName, $tmpFile); | ||||||||||||||||||||||||||||||||||||||||||||
| 71 | $self->printf("Using separator %s, quote char %s, escape char %s\n", | ||||||||||||||||||||||||||||||||||||||||||||
| 72 | $csv->{'sep_char'}, $csv->{'quote_char'}, | ||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | $csv->{'escape_char'}); | |||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | $dbhf->{'csv_tables'}->{$table} = { | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 'file' => $tmpFile | ||||||||||||||||||||||||||||||||||||||||||||
| 77 | }; | ||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | my $query = "SELECT * FROM $table"; | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | if ($debug) { $self->print("SELECT query: $query\n") } | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | my $sth = $dbhf->prepare($query); | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | $sth->execute(); | |||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | if (my $namevar = $attr->{'names'}) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | $self->{$namevar} = $sth->{'NAME'}; | |||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | if (my $templatevar = $attr->{'template'}) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | my $template = ''; | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | for (my $i = 0; $i <= $sth->{'NUM_OF_FIELDS'}; $i++) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | $template .= "<TD>\$r->$i\$</TD>"; | |||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | $self->{$templatevar} = $template . "\n"; | |||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | if ($self->{'debug'}) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | $self->print("Template = $template\n"); | |||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | my $numRecords = 0; | |||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | my $dbh = $self->{'dbh'}; | |||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | $query = "DELETE FROM $table"; | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | if ($debug) { $self->print("Cleaning query: $query\n") } | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | $dbh->do($query); | |||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | $query = "INSERT INTO $table VALUES ("; | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | my $add = ""; | |||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | for (my $i = 0; $i <= $sth->{'NUM_OF_FIELDS'}; $i++) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | $query .= $add . "?"; | |||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | $add = ", "; | |||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | $query .= ")"; | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | if ($debug) { $self->print("INSERT query: $query\n") } | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | my $sthi = $dbh->prepare($query); | |||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | my @rows; | |||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | my $result = $attr->{'result'}; | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | while (my $ref = $sth->fetchrow_arrayref()) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | $sthi->execute(++$numRecords, @$ref); | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | if ($result) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | push(@rows, [$numRecords, @$ref]); | |||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | if ($result) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | $self->{$result} = \@rows; | |||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | ''; | |||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | sub _ep_shop_download { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ep_shop_download: not called CC=11 SCAR=48.8
| |||||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | my $self = shift; my $attr = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | my $cgi = $self->{'cgi'}; | |||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | my $dbh = $self->{'dbh'}; | |||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | my $table = $attr->{'table'} || die "Missing table name"; | ||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$attr->{'table'} || die('Missing table name')
MC/DC0%0/1
$attr->{'table'} || die('Missing table name')
$attr->{'table'}
Truth table0%0/2
A
A= $attr->{'table'}
| |||||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | my $removeId = $attr->{'removeid'} || 1; | ||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$attr->{'removeid'} || 1
MC/DC0%0/1
$attr->{'removeid'} || 1
$attr->{'removeid'}
Truth table0%0/2
A
A= $attr->{'removeid'}
| |||||||||||||||||||||||||||||||||||||||||||||
| 136 | my $csv = Text::CSV_XS->new | ||||||||||||||||||||||||||||||||||||||||||||
| 137 | ({'binary' => 1, | ||||||||||||||||||||||||||||||||||||||||||||
| 138 | 'eol' => "\r\n", | ||||||||||||||||||||||||||||||||||||||||||||
| 139 | 'sep_char' => $attr->{'sep'} || ';', | ||||||||||||||||||||||||||||||||||||||||||||
| 140 | 'escape_char' => $attr->{'escape'} || '"', | ||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | 'quote_char' => $attr->{'quote'} || $attr->{'escape'} || '"' }); | ||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/9
$attr->{'sep'} || ';'
$attr->{'escape'} || '"'
$attr->{'quote'} || $attr->{'escape'} || '"'
$attr->{"quote"} or $attr->{"escape"}
MC/DC0%0/1
$attr->{'sep'} || ';'
$attr->{'sep'}
MC/DC0%0/1
$attr->{'escape'} || '"'
$attr->{'escape'}
MC/DC0%0/2
$attr->{'quote'} || $attr->{'escape'} || '"'
$attr->{"quote"}
$attr->{"escape"}
Truth table0%0/2
A
A= $attr->{'sep'}
Truth table0%0/2
A
A= $attr->{'escape'}
Truth table0%0/3
A or B
A= $attr->{"quote"}B= $attr->{"escape"}
| |||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | my $sth = $dbh->prepare("SELECT * FROM $table"); | |||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | $sth->execute(); | |||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | $self->print($cgi->header(-type => 'text/plain')); | |||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | my $names = [@{$sth->{'NAME'}}]; | |||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | ▶ | if ($removeId) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | shift @$names; | |||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | ▶ | if ($self->{'debug'}) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | $self->print("Names = ", join(", ", @$names), "\n"); | |||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | $csv->print($self, [@$names]); | |||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | ▶ | while (my $ref = $sth->fetchrow_arrayref()) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | ▶ | if ($removeId) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | my @row = @$ref; | |||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | shift @row; | |||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | $ref = \@row; | |||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | $csv->print($self, $ref); | |||||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | $self->Stop(); | |||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | ''; | |||||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | ▶ | sub _ep_shop_prefs_write { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ep_shop_prefs_write: not called CC=10 SCAR=47.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | my $self = shift; my $attr = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | ▶ | my $table = $attr->{'table'} || 'prefs'; | ||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$attr->{'table'} || 'prefs'
MC/DC0%0/1
$attr->{'table'} || 'prefs'
$attr->{'table'}
Truth table0%0/2
A
A= $attr->{'table'}
| |||||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | my $pvar = $attr->{'var'} || 'prefs'; | ||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$attr->{'var'} || 'prefs'
MC/DC0%0/1
$attr->{'var'} || 'prefs'
$attr->{'var'}
Truth table0%0/2
A
A= $attr->{'var'}
| |||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | ▶ | my $prefs = $self->{$pvar} || die "No prefs set in variable $pvar"; | ||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{$pvar} || die("No prefs set in variable $pvar")
MC/DC0%0/1
$self->{$pvar} || die("No prefs set in variable $pvar")
$self->{$pvar}
Truth table0%0/2
A
A= $self->{$pvar}
| |||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | ▶ | my $tvar = $attr->{'tvar'} || 'prefs'; | ||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$attr->{'tvar'} || 'prefs'
MC/DC0%0/1
$attr->{'tvar'} || 'prefs'
$attr->{'tvar'}
Truth table0%0/2
A
A= $attr->{'tvar'}
| |||||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | ▶ | my $dbh = $self->{'dbh'} || die "Missing database handle"; | ||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'dbh'} || die('Missing database handle')
MC/DC0%0/1
$self->{'dbh'} || die('Missing database handle')
$self->{'dbh'}
Truth table0%0/2
A
A= $self->{'dbh'}
| |||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | ▶ | if ($self->{'debug'}) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | $self->print("Saving prefs: ", join(" ", %$prefs), "\n"); | |||||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | my $uquery = "UPDATE $table SET val = ? WHERE var = " | |||||||||||||||||||||||||||||||||||||||||||
| 180 | . $dbh->quote($tvar); | ||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | my $freezed_prefs = Storable::nfreeze($prefs); | |||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | eval {$dbh->do($uquery, undef, $freezed_prefs) }; | |||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | my $error = $@; | |||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | my $cquery = "CREATE TABLE $table (" | |||||||||||||||||||||||||||||||||||||||||||
| 186 | . " var VARCHAR(32) NOT NULL," | ||||||||||||||||||||||||||||||||||||||||||||
| 187 | . " val BLOB NOT NULL)"; | ||||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | ▶ | if (eval { $dbh->do($cquery) }) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | $cquery = "INSERT INTO $table VALUES (" . $dbh->quote($tvar) | |||||||||||||||||||||||||||||||||||||||||||
| 190 | . ", ?)"; | ||||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | eval { $dbh->do($cquery, undef, $freezed_prefs) }; | |||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | die "While updating: Catched error\n$error\n" . | |||||||||||||||||||||||||||||||||||||||||||
| 195 | "Update query was: $uquery\n" . | ||||||||||||||||||||||||||||||||||||||||||||
| 196 | "While inserting: Catched error\n$@\n" . | ||||||||||||||||||||||||||||||||||||||||||||
| 197 | "Insert query was: $cquery\n"; | ||||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | ''; | |||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | sub _ep_shop_prefs_read { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ep_shop_prefs_read: not called CC=10 SCAR=47.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | my $self = shift; my $attr = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | my $cgi = $self->{'cgi'}; | |||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | my $dbh = $self->{'dbh'}; | |||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | ▶ | my $table = $self->{'table'} || 'prefs'; | ||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'table'} || 'prefs'
MC/DC0%0/1
$self->{'table'} || 'prefs'
$self->{'table'}
Truth table0%0/2
A
A= $self->{'table'}
| |||||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | ▶ | my $pvar = $attr->{'var'} || 'prefs'; | ||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$attr->{'var'} || 'prefs'
MC/DC0%0/1
$attr->{'var'} || 'prefs'
$attr->{'var'}
Truth table0%0/2
A
A= $attr->{'var'}
| |||||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | ▶ | my $tvar = $attr->{'tvar'} || 'prefs'; | ||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$attr->{'tvar'} || 'prefs'
MC/DC0%0/1
$attr->{'tvar'} || 'prefs'
$attr->{'tvar'}
Truth table0%0/2
A
A= $attr->{'tvar'}
| |||||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | my $prefs = $self->{$pvar}; | |||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||
| 212 | # Read Prefs | ||||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | ▶ | if (!$prefs) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | my $ref; | |||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | eval { | |||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | my $sth = $dbh->prepare("SELECT val FROM prefs WHERE var = ?"); | |||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | $sth->execute($tvar); | |||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | $ref = $sth->fetchrow_arrayref(); | |||||||||||||||||||||||||||||||||||||||||||
| 219 | }; | ||||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | ▶ | $prefs = $ref ? Storable::thaw($ref->[0]) : {}; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | $self->{$pvar} = $prefs; | |||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | ▶ | if ($attr->{'write'} && defined($cgi->{'prefs_company'})) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$attr->{"write"} and defined $cgi->{"prefs_company"}
MC/DC0%0/2
$attr->{"write"} and defined $cgi->{"prefs_company"}
$attr->{"write"}
defined $cgi->{"prefs_company"}
Truth table0%0/3
A and B
A= $attr->{"write"}B= defined $cgi->{"prefs_company"}
| |||||||||||||||||||||||||||||||||||||||||||||
| 225 | # Save Prefs | ||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | foreach my $var ($cgi->param()) { | |||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | ▶ | if ($var =~ /^prefs_(.*)/) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | $prefs->{$1} = $cgi->param($var); | |||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | $self->_ep_shop_prefs_write($attr); | |||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | ''; | |||||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||
| 238 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||
| 240 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||