| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 48 | 0 | $_[0] = $pic; | |||||||||
| 49 | } | ||||||||||