XTaTIK/Common.pm

filter: Statementstmt 56.4% 22 / 39 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 6 / 8 Podpod 0.0% 0 / 2 totaltotal 49.1% 28 / 57 CC 6 SCAR 25.6
CC
6
Cov
47%
set_product_pic
30.0
n_to_br
6.0
BEGIN
1.0
CRAP 12.9
« XTaTIK/Controller/Root.pm ↑ Summary XTaTIK/Controller/Cart.pm »
1 package XTaTIK::Common;
2  
3 4 our $VERSION = '0.005003'; # VERSION
4  
5 4 require Exporter;
6 4 @ISA = qw(Exporter);
7 4 @EXPORT_OK = qw(n_to_br set_product_pic);
8  
9 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use HTML::Entities;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use File::Glob qw/bsd_glob/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 ▶use File::Spec::Functions qw/catfile splitpath/;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 ▶use experimental 'postderef';
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 0 ▶sub n_to_br {
Subroutine n_to_br: not called CC=2 SCAR=17.9
Pod undocumented
17 0 my $data = shift;
18 0 ▶ return '' unless length $data;
Branch: 1 branch
BranchTrueFalseTotal
unless length $data 0 0 0
19 0 return encode_entities($data) =~ s/\n\r?|\r\n/<br>/gr;
20 }
21  
22 0 ▶sub set_product_pic {
Subroutine set_product_pic: not called CC=5 SCAR=34.0
Pod undocumented
23 0 my $c = shift;
24 0 my ( $pic, $num ) = @_;
25  
26 # This product has a set pic; check all exist and return
27 0 ▶ if ( length $pic ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $pic) 0 0 0
28 0 $pic = join '?',
29 grep $c->app->static->file( catfile 'product-pics', $_ ),
30 split /\?/, $pic;
31  
32 0 ▶ $pic = 'nopic.png' unless length $pic;
Branch: 1 branch
BranchTrueFalseTotal
unless length $pic 0 0 0
33 0 $_[0] = $pic;
34 0 return;
35 }
36  
37 # No pic set; auto-find them using product number
38 0 $num =~ s{[\\/:*?"<>|]}{_}g; # sub disallowed path chars to underscores
39 0 my @pics;
40 0 for ( $c->app->static->paths->@* ) {
41 0 push @pics, map +(splitpath $_)[-1], grep -r,
42 catfile($_, 'product-pics', "$num.jpg"),
43 bsd_glob catfile $_, 'product-pics', $num . '___*.jpg';
44 }
45  
46 0 $pic = join '?', @pics;
47 0 ▶ $pic = 'nopic.png' unless length $pic;
Branch: 1 branch
BranchTrueFalseTotal
unless length $pic 0 0 0
48 0 $_[0] = $pic;
49 }
« XTaTIK/Controller/Root.pm ↑ Summary XTaTIK/Controller/Cart.pm »