File Coverage

blib/lib/Barcode/DataMatrix.pm
Criterion Covered Total %
statement 27 27 100.0
branch 2 2 100.0
condition n/a
subroutine 6 6 100.0
pod 1 1 100.0
total 36 36 100.0


line stmt bran cond sub pod time code
1             package Barcode::DataMatrix;
2 2     2   43655 use Moo;
  2         30291  
  2         12  
3 2     2   5270 use Type::Tiny;
  2         43579  
  2         78  
4 2     2   1832 use Types::Standard qw(:all);
  2         105563  
  2         21  
5 2     2   86724 use Type::Utils qw(enum);
  2         9573  
  2         20  
6 2     2   2398 use Barcode::DataMatrix::Engine ();
  2         6  
  2         567  
7              
8             our $VERSION = '0.07';
9              
10             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             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. 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 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     12 1 191265 my ($self, $text) = @_;
70              
71 12         98 my $engine = Barcode::DataMatrix::Engine->new(
72             $text,
73             $self->encoding_mode,
74             undef, # size
75             $self->process_tilde,
76             );
77              
78 12         29 my $rows = $engine->{rows};
79 12         23 my $cols = $engine->{cols};
80 12         19 my $bitmap = $engine->{bitmap};
81 12         22 my $rv = [];
82 12         34 for my $r (0 .. $rows - 1) {
83 390         510 my $row = [];
84 390         603 for my $c (0 .. $cols - 1) {
85 17212 100       34467 push @$row, ($bitmap->[$c]->[$r] ? 1 : 0);
86             }
87 390         656 push @$rv, $row;
88             }
89              
90 12         473 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 (default), C, C, C, C, or C.
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
105              
106             =cut
107              
108             =head1 AUTHORS
109              
110             Mons Anderson C<< >> (GD::Barcode::DataMatrix at L, from which this distribution originates)
111              
112             Mark A. Stratman, C<< >>
113              
114             Paul Cochrane, L
115              
116             =head1 SOURCE REPOSITORY
117              
118             L
119              
120             =head1 SEE ALSO
121              
122             =over 4
123              
124             =item L
125              
126             =item L
127              
128             =item L
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             1; # End of Barcode::DataMatrix