DataMatrix.pm

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