File Coverage

blib/lib/SVG/Barcode/Code128.pm
Criterion Covered Total %
statement 42 42 100.0
branch n/a
condition 1 3 33.3
subroutine 12 12 100.0
pod 1 1 100.0
total 56 58 96.5


line stmt bran cond sub pod time code
1             package SVG::Barcode::Code128;
2 2     2   145522 use parent 'SVG::Barcode';
  2         612  
  2         12  
3 2     2   24686 use strict;
  2         6  
  2         66  
4 2     2   13 use warnings;
  2         5  
  2         48  
5 2     2   10 use utf8;
  2         4  
  2         12  
6 2     2   52 use v5.24;
  2         7  
7 2     2   11 use feature 'signatures';
  2         4  
  2         179  
8 2     2   11 no warnings 'experimental::signatures';
  2         5  
  2         66  
9              
10 2     2   11 use Exporter 'import';
  2         4  
  2         102  
11             our @EXPORT_OK = qw|plot_code128|;
12              
13 2     2   1238 use Barcode::Code128;
  2         10952  
  2         184  
14              
15             our $VERSION = '0.11';
16              
17 2         584 use constant DEFAULTS => {
18             lineheight => 30,
19             linewidth => 1,
20             textsize => 10,
21 2     2   21 };
  2         3  
22              
23             SVG::Barcode::_param(__PACKAGE__, $_, DEFAULTS->{$_}) for keys DEFAULTS->%*;
24              
25             # functions
26              
27 3     3 1 13060 sub plot_code128 ($text, %params) {
  2         6  
  2         5  
  2         15  
28 2         16 return __PACKAGE__->new(%params)->plot($text);
29             }
30              
31             # internal methods
32              
33 4     4   31223 sub _plot ($self, $text) {
  4         8  
  4         28  
  4         13  
34 4   33     41 $self->{plotter} ||= Barcode::Code128->new;
35              
36 4         79 my @code = split //, $self->{plotter}->barcode($text);
37 4         1327 $self->_plot_1d(\@code, '#');
38 4         3263 $self->_plot_text($text);
39             }
40              
41             1;
42              
43             =encoding utf8
44              
45             =head1 NAME
46              
47             SVG::Barcode::Code128 - Generator for SVG based Code 128 barcodes
48              
49             =head1 SYNOPSIS
50              
51             use SVG::Barcode::Code128;
52              
53             my $code128 = SVG::Barcode::Code128->new;
54             my $svg = $code128->plot('https://perldoc.pl');
55              
56             $code128->linewidth; # 1
57             $code128->lineheight; # 30
58             $code128->textsize; # 10
59             # from SVG::Barcode:
60             $code128->foreground; # black
61             $code128->background; # white
62             $code128->margin; # 2
63             $code128->id;
64             $code128->class;
65             $code128->width;
66             $code128->height;
67             $code128->scale;
68              
69             my %params = (
70             lineheight => 40,
71             textsize => 0,
72             );
73             $code128 = SVG::Barcode::Code128->new(%params);
74              
75             # use as function
76             use SVG::Barcode::Code128 'plot_code128';
77              
78             my $svg = plot_code128('https://perldoc.pl', %params);
79              
80             =head1 DESCRIPTION
81              
82             L is a generator for SVG based Code 128 barcodes.
83              
84             =head1 FUNCTIONS
85              
86             =head2 plot_code128
87              
88             use SVG::Barcode::Code128 'plot_code128';
89              
90             $svg = plot_code128($text, %params);
91              
92             Returns a Code 128 barcode using the provided text and parameters.
93              
94             =head1 CONSTRUCTOR
95              
96             =head2 new
97              
98             $code128 = SVG::Barcode::Code128->new; # create with defaults
99             $code128 = SVG::Barcode::Code128->new(\%params);
100              
101             Creates a new Code 128 plotter. Inherited from L.
102              
103             =head1 METHODS
104              
105             =head2 plot
106              
107             Creates a SVG code. Inherited from L.
108              
109             =head1 PARAMETERS
110              
111             Inherited from L:
112             L,
113             L,
114             L,
115             L,
116             L,
117             L,
118             L,
119             L.
120              
121             =head2 lineheight
122              
123             $value = $code128->lineheight;
124             $code128 = $code128->lineheight($newvalue);
125             $code128 = $code128->lineheight(''); # 30
126              
127             Getter and setter for the height of a line. Default C<30>.
128              
129             =head2 linewidth
130              
131             $value = $code128->linewidth;
132             $code128 = $code128->linewidth($newvalue);
133             $code128 = $code128->linewidth(''); # 1
134              
135             Getter and setter for the width of a single line. Default C<1>.
136              
137             =head2 textsize
138              
139             $value = $code128->textsize;
140             $code128 = $code128->textsize($newvalue);
141             $code128 = $code128->textsize(''); # 10
142              
143             Getter and setter for the size of the text a the bottom. C<0> hides the text. Default C<10>.
144              
145             =head1 SEE ALSO
146              
147             L, L.
148              
149             =head1 AUTHOR & COPYRIGHT
150              
151             © 2019 by Tekki (Rolf Stöckli).
152              
153             This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0.
154              
155             =cut