Barcode/Matrix2of5.pm

filter: Statementstmt 67.8% 40 / 59 Branchbran 56.2% 9 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 80.0% 8 / 10 Podpod 60.0% 3 / 5 totaltotal 66.6% 60 / 90 CC 9 SCAR 14.5
CC
9
Cov
65%
plot
12.0
new
6.0
barcodeWk
4.0
CRAP 4.3
« Barcode/COOP2of5.pm ↑ Summary Barcode/IATA2of5.pm »
1 package GD::Barcode::Matrix2of5;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use GD::Barcode;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use parent qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use vars qw($VERSION @ISA $errStr);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 @ISA = qw(GD::Barcode Exporter);
9 1 our $VERSION = '2.02';
10  
11 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
12 0 my ( $sClass, $sTxt ) = @_;
13 0 $errStr = '';
14 0 my $oThis = {};
15 0 bless $oThis, $sClass;
16 0 ▶ return if ( $errStr = $oThis->init($sTxt) );
Branch: 1 branch
BranchTrueFalseTotal
if $GD::Barcode::Matrix2of5::errStr = $oThis->init($sTxt) 0 0 0
17 0 return $oThis;
18 }
19  
20 1 ▶sub init {
Subroutine init: called CC=2 SCAR=7.0
Pod undocumented
21 1 my ( $oThis, $sTxt ) = @_;
22  
23 #Check
24 1 ▶ return 'Invalid Characters' if ( $sTxt =~ /[^0-9]/ );
Branch: 1 branch
BranchTrueFalseTotal
if $sTxt =~ /[^0-9]/ 0 1 1
25  
26 1 $oThis->{text} = $sTxt;
27 1 return '';
28 }
29  
30 11 ▶sub barcodeWk {
Subroutine barcodeWk: called CC=4 SCAR=13.9
Pod undocumented
31 11 my ($sPtn) = @_;
32 11 my $sRes = '';
33 11 my $sClr = '1';
34 11 ▶ for ( my $i = 0 ; $i < length($sPtn) ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < length $sPtn) 55 11 66
35 55 ▶ $sRes .= ( substr( $sPtn, $i, 1 ) eq '1' ) ? $sClr x 3 : $sClr;
Branch: 1 branch
BranchTrueFalseTotal
substr($sPtn, $i, 1) eq '1' ? : 20 35 55
36 55 ▶ $sClr = ( $sClr eq '1' ) ? '0' : '1';
Branch: 1 branch
BranchTrueFalseTotal
$sClr eq '1' ? : 33 22 55
37 }
38 11 return $sRes;
39 }
40  
41 1 ▶sub barcode {
Subroutine barcode: called CC=2 SCAR=6.9
Pod documented
42 1 my ($oThis) = @_;
43 1 my $i;
44 my $sRes;
45 1 my $sTxt = $oThis->{text};
46 1 my $rhPtn = {
47 'START' => '10000',
48 '0' => '00110',
49 '1' => '10001',
50 '2' => '01001',
51 '3' => '11000',
52 '4' => '00101',
53 '5' => '10100',
54 '6' => '01100',
55 '7' => '00011',
56 '8' => '10010',
57 '9' => '01010',
58 'STOP' => '10000',
59 };
60 1 $sRes = barcodeWk( $rhPtn->{START} );
61 1 ▶ for ( $i = 0 ; $i < length($sTxt) ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < length $sTxt) 9 1 10
62 9 $sRes .= '0'; #GAP
63 9 $sRes .= barcodeWk( $rhPtn->{ substr( $sTxt, $i, 1 ) } );
64 }
65 1 $sRes .= '0'; #GAP
66 1 $sRes .= barcodeWk( $rhPtn->{STOP} );
67 1 return $sRes;
68 }
69  
70 0 ▶sub plot {
Subroutine plot: not called CC=3 SCAR=24.8
Pod documented
71 0 my ( $oThis, %hParam ) = @_;
72  
73 0 my $sTxtWk = $oThis->{text};
74 0 my $sPtn = $oThis->barcode();
75  
76 #Create Image
77 0 ▶ my $iHeight = ( $hParam{Height} ) ? $hParam{Height} : 50;
Branch: 1 branch
BranchTrueFalseTotal
$hParam{'Height'} ? : 0 0 0
78 0 my ( $oGd, $cBlack );
79 0 ▶ if ( $hParam{NoText} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hParam{'NoText'}) { } 0 0 0
80 0 ( $oGd, $cBlack ) =
81 GD::Barcode::plot( $sPtn, length($sPtn), $iHeight, 0, 0 );
82 }
83 else {
84 0 require GD;
85 0 my ( $fW, $fH ) = ( GD::Font->Small->width, GD::Font->Small->height );
86 0 my $iWidth = length($sPtn);
87  
88 #Bar Image
89 0 ( $oGd, $cBlack ) =
90 GD::Barcode::plot( $sPtn, $iWidth, $iHeight, $fH, 0 );
91  
92 #String
93 0 $oGd->string(
94 GD::Font->Small,
95 ( length($sPtn) - $fW * ( length($sTxtWk) ) ) / 2,
96 $iHeight - $fH,
97 $sTxtWk, $cBlack
98 );
99 }
100 0 return $oGd;
101 }
102 1 1;
103 __END__
« Barcode/COOP2of5.pm ↑ Summary Barcode/IATA2of5.pm »