Barcode/IATA2of5.pm untested

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