File Coverage

blib/lib/Barcode/DataMatrix.pm
Criterion Covered Total %
statement 18 18 100.0
branch 2 2 100.0
condition n/a
subroutine 3 3 100.0
pod 1 1 100.0
total 24 24 100.0


line stmt bran cond sub pod time code
1             package Barcode::DataMatrix;
2 2     2   27679 use Moo;
  2         18404  
  2         9  
3 2     2   2792 use Barcode::DataMatrix::Engine ();
  2         4  
  2         397  
4              
5             our $VERSION = '0.08';
6              
7             has 'encoding_mode' => (
8             is => 'ro',
9             isa => sub { my $type = shift; for (qw(ASCII C40 TEXT BASE256 NONE AUTO)) { return 1 if $type eq $_ } return 0; },
10             default => 'AUTO',
11             documentation => 'The encoding mode for the data matrix. Can be one of: ASCII C40 TEXT BASE256 NONE AUTO',
12             );
13             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. 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 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     12 1 18256 my ($self, $text) = @_;
63              
64 12         97 my $engine = Barcode::DataMatrix::Engine->new(
65             $text,
66             $self->encoding_mode,
67             undef, # size
68             $self->process_tilde,
69             );
70              
71 12         18 my $rows = $engine->{rows};
72 12         17 my $cols = $engine->{cols};
73 12         16 my $bitmap = $engine->{bitmap};
74 12         16 my $rv = [];
75 12         29 for my $r (0 .. $rows - 1) {
76 390         285 my $row = [];
77 390         336 for my $c (0 .. $cols - 1) {
78 17212 100       16878 push @$row, ($bitmap->[$c]->[$r] ? 1 : 0);
79             }
80 390         371 push @$rv, $row;
81             }
82              
83 12         361 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 (default), C, C, C, C, or C.
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
98              
99             =cut
100              
101             =head1 AUTHORS
102              
103             Mons Anderson C<< >> (GD::Barcode::DataMatrix at L, from which this distribution originates)
104              
105             Mark A. Stratman, C<< >>
106              
107             Paul Cochrane, L
108              
109             =head1 SOURCE REPOSITORY
110              
111             L
112              
113             =head1 SEE ALSO
114              
115             =over 4
116              
117             =item L
118              
119             =item L
120              
121             =item L
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             1; # End of Barcode::DataMatrix