DataMatrix.pm

filter: Statementstmt 100% 31 / 31 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 100% 40 / 40 CC 4 SCAR 8.5
CC
4
Cov
100%
barcode
4.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.3
« DataMatrix/Reed.pm ↑ Summary DataMatrix/Constants.pm »
1 package Barcode::DataMatrix;
2 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use Type::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Types::Standard qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Type::Utils qw(enum);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Barcode::DataMatrix::Engine ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 our $VERSION = '0.07';
9  
10 2 has 'encoding_mode' => (
11 is => 'ro',
12 isa => enum([qw[ ASCII C40 TEXT BASE256 NONE AUTO ]]),
13 isa => enum(BCDM_EncodingMode => [qw[ ASCII C40 TEXT BASE256 NONE AUTO ]]),
14 required => 1,
15 default => 'AUTO',
16 documentation => 'The encoding mode for the data matrix. Can be one of: ASCII C40 TEXT BASE256 NONE AUTO',
17 );
18 2 has 'process_tilde' => (
19 is => 'ro',
20 isa => Bool,
21 required => 0,
22 default => 0,
23 documentation => 'Set to true to indicate the tilde character "~" is being used to recognize special characters.',
24 );
25  
26 =head1 NAME
27  
28 Barcode::DataMatrix - Generate data for Data Matrix barcodes
29  
30 =head1 SYNOPSIS
31  
32 use Barcode::DataMatrix;
33 my $data = Barcode::DataMatrix->new->barcode('MONKEY');
34 for my $row (@$data) {
35 print for map { $_ ? "#" : ' ' } @$row;
36 print "\n";
37 }
38  
39 =cut
40  
41 =head1 DESCRIPTION
42  
43 This class is used to generate data for Data Matrix barcodes. It is primarily
44 useful as a data source for barcode modules that do rendering,
45 such as L<HTML::Barcode::DataMatrix>. You can easily make a version that
46 renders an image, PDF, or anything else.
47  
48 =head1 METHODS
49  
50 =head2 new (%attributes)
51  
52 Instantiate a new Barcode::DataMatrix object. The C<%attributes> hash
53 can take any of the other L<attributes|/ATTRIBUTES> listed below.
54  
55 =cut
56  
57 =head2 barcode ($text)
58  
59 Generate barcode data representing the C<$text> string. This returns
60 an array ref of rows in the data matrix, each containing array refs of
61 cells within that row. The cells are true and false values
62 that represent filled or empty squares.
63  
64 This can throw an exception if it's unable to generate the barcode data.
65  
66 =cut
67  
68 sub barcode {
69 12 ▶ my ($self, $text) = @_;
Subroutine barcode: called CC=4 SCAR=13.9
Pod documented
70  
71 12 my $engine = Barcode::DataMatrix::Engine->new(
72 $text,
73 $self->encoding_mode,
74 undef, # size
75 $self->process_tilde,
76 );
77  
78 12 my $rows = $engine->{rows};
79 12 my $cols = $engine->{cols};
80 12 my $bitmap = $engine->{bitmap};
81 12 my $rv = [];
82 12 for my $r (0 .. $rows - 1) {
83 390 my $row = [];
84 390 for my $c (0 .. $cols - 1) {
85 17212 ▶ push @$row, ($bitmap->[$c]->[$r] ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$bitmap->[$c][$r] ? : 9618 7594 17212
86 }
87 390 push @$rv, $row;
88 }
89  
90 12 return $rv;
91 }
92  
93 =head1 ATTRIBUTES
94  
95 =head2 encoding_mode
96  
97 The encoding mode for the data matrix. Can be one of:
98 C<AUTO> (default), C<ASCII>, C<C40>, C<TEXT>, C<BASE256>, or C<NONE>.
99  
100 =head2 process_tilde
101  
102 Set to true to indicate the tilde character "~" is being used to recognize
103 special characters. See this page for more information:
104 L<http://www.idautomation.com/datamatrixfaq.html>
105  
106 =cut
107  
108 =head1 AUTHORS
109  
110 Mons Anderson C<< <inthrax@gmail.com> >> (GD::Barcode::DataMatrix at L<https://github.com/Mons/perl-ex/>, from which this distribution originates)
111  
112 Mark A. Stratman, C<< <stratman@gmail.com> >>
113  
114 Paul Cochrane, L<https://github.com/paultcochrane>
115  
116 =head1 SOURCE REPOSITORY
117  
118 L<http://github.com/mstratman/Barcode-DataMatrix>
119  
120 =head1 SEE ALSO
121  
122 =over 4
123  
124 =item L<HTML::Barcode::DataMatrix>
125  
126 =item L<http://grandzebu.net/informatique/codbar-en/datamatrix.htm>
127  
128 =item L<http://www.idautomation.com/datamatrixfaq.html>
129  
130 =back
131  
132 =head1 LICENSE AND COPYRIGHT
133  
134 Copyright 2015 the AUTHORs listed above.
135  
136 This program is free software; you can redistribute it and/or modify it
137 under the terms of either: the GNU General Public License as published
138 by the Free Software Foundation; or the Artistic License.
139  
140 See http://dev.perl.org/licenses/ for more information.
141  
142  
143 =cut
144  
145 2 1; # End of Barcode::DataMatrix
« DataMatrix/Reed.pm ↑ Summary DataMatrix/Constants.pm »