| 1 | package App::ZofCMS::Plugin::Barcode; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | our $VERSION = '1.001010'; # VERSION | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use GD::Barcode; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use base 'App::ZofCMS::Plugin::Base'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 0 | ▶ | sub _key { 'plug_barcode' } | ||||||||||||||||||||||||||
|
Subroutine
_key: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 12 | 0 | ▶ | sub _defaults { | ||||||||||||||||||||||||||
|
Subroutine
_defaults: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 13 | 0 | code => undef, | |||||||||||||||||||||||||||
| 14 | format => 'png', # gif or png | ||||||||||||||||||||||||||||
| 15 | type => 'UPCA', | ||||||||||||||||||||||||||||
| 16 | no_text => 0, | ||||||||||||||||||||||||||||
| 17 | height => 50, | ||||||||||||||||||||||||||||
| 18 | file => undef, | ||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||
| 20 | 0 | ▶ | sub _do { | ||||||||||||||||||||||||||
|
Subroutine
_do: not called CC=13 SCAR=52.0
| |||||||||||||||||||||||||||||
| 21 | 0 | my ( $self, $conf, $t, $q, $config ) = @_; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | $conf->{code} = $conf->{code}->( $t, $q, $config ) | ||||||||||||||||||||||||||||
| 24 | 0 | ▶ | if ref $conf->{code} eq 'CODE'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | return | ||||||||||||||||||||||||||||
| 27 | unless defined $conf->{code} | ||||||||||||||||||||||||||||
| 28 | 0 | ▶ | and length $conf->{code}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $conf->{"code"} and length $conf->{"code"}
MC/DC0%0/2
defined $conf->{"code"} and length $conf->{"code"}
defined $conf->{"code"}
length $conf->{"code"}
Truth table0%0/3
A and B
A= defined $conf->{"code"}B= length $conf->{"code"}
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | $conf->{type} = $conf->{type}->( $t, $q, $config ) | ||||||||||||||||||||||||||||
| 31 | 0 | ▶ | if ref $conf->{type} eq 'CODE'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | return | ||||||||||||||||||||||||||||
| 34 | unless defined $conf->{type} | ||||||||||||||||||||||||||||
| 35 | 0 | ▶ | and length $conf->{type}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $conf->{"type"} and length $conf->{"type"}
MC/DC0%0/2
defined $conf->{"type"} and length $conf->{"type"}
defined $conf->{"type"}
length $conf->{"type"}
Truth table0%0/3
A and B
A= defined $conf->{"type"}B= length $conf->{"type"}
| |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | my $bar = GD::Barcode->new( @$conf{ qw/type code/ } ); | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 0 | ▶ | unless ( $bar ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 0 | $t->{t}{plug_barcode_error} = $GD::Barcode::errStr; | |||||||||||||||||||||||||||
| 41 | 0 | return; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | if ( defined $conf->{file} and length $conf->{file} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $conf->{"file"} and length $conf->{"file"}
MC/DC0%0/2
defined $conf->{"file"} and length $conf->{"file"}
defined $conf->{"file"}
length $conf->{"file"}
Truth table0%0/3
A and B
A= defined $conf->{"file"}B= length $conf->{"file"}
| |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | if ( open my $fh, '>', $conf->{file} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 0 | binmode $fh; | |||||||||||||||||||||||||||
| 47 | print $fh $conf->{format} eq 'png' | ||||||||||||||||||||||||||||
| 48 | ? $bar->plot( Height => $conf->{height}, NoText => $conf->{no_text} )->png | ||||||||||||||||||||||||||||
| 49 | 0 | ▶ | : $bar->plot( Height => $conf->{height}, NoText => $conf->{no_text} )->gif; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | else { | ||||||||||||||||||||||||||||
| 52 | 0 | $t->{t}{plug_barcode_error} = $!; | |||||||||||||||||||||||||||
| 53 | 0 | return; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | else { | ||||||||||||||||||||||||||||
| 57 | 0 | binmode STDOUT; | |||||||||||||||||||||||||||
| 58 | 0 | ▶ | if ( $conf->{format} eq 'png' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 0 | print "Content-Type: image/png\n\n"; | |||||||||||||||||||||||||||
| 60 | 0 | print $bar->plot( Height => $conf->{height}, NoText => $conf->{no_text} )->png; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | else { | ||||||||||||||||||||||||||||
| 63 | 0 | print "Content-Type: image/gif\n\n"; | |||||||||||||||||||||||||||
| 64 | 0 | print $bar->plot( Height => $conf->{height}, NoText => $conf->{no_text} )->gif; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | 0 | exit; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 1 | 1; | |||||||||||||||||||||||||||
| 71 | __END__ | ||||||||||||||||||||||||||||