| 1 | package HTML::Barcode::Code128; | ||||||||||
| 2 | 2 | ▶ | use Any::Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 2 | extends 'HTML::Barcode::1D'; | |||||||||
| 4 | 2 | ▶ | use Barcode::Code128; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 2 | our $VERSION = '0.11'; | |||||||||
| 7 | |||||||||||
| 8 | has '_code128' => ( | ||||||||||
| 9 | is => 'ro', | ||||||||||
| 10 | 0 | ▶ | default => sub { Barcode::Code128->new }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 11 | 2 | ); | |||||||||
| 12 | |||||||||||
| 13 | sub barcode_data { | ||||||||||
| 14 | 1 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
barcode_data: called CC=2 SCAR=11.6
Pod
documented
| |||||||||||
| 15 | 1 | my $data_str = $self->_code128->barcode($self->text); | |||||||||
| 16 | return [ | ||||||||||
| 17 | 0 | ▶ | map { $_ eq '#' ? 1 : 0 } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 18 | split //, $data_str | ||||||||||
| 19 | ]; | ||||||||||
| 20 | } | ||||||||||
| 21 | |||||||||||
| 22 | =head1 NAME | ||||||||||
| 23 | |||||||||||
| 24 | HTML::Barcode::Code128 - Generate HTML representations of Code 128 barcodes | ||||||||||
| 25 | |||||||||||
| 26 | =head1 SYNOPSIS | ||||||||||
| 27 | |||||||||||
| 28 | L<Barcode::Code128> is required by this class, so please install it first. | ||||||||||
| 29 | |||||||||||
| 30 | my $code = HTML::Barcode::Code128->new(text => 'MONKEY'); | ||||||||||
| 31 | print $code->render; | ||||||||||
| 32 | |||||||||||
| 33 | =head1 DESCRIPTION | ||||||||||
| 34 | |||||||||||
| 35 | This class allows you to easily create HTML representations of Code 128 barcodes. | ||||||||||
| 36 | |||||||||||
| 37 | =begin html | ||||||||||
| 38 | |||||||||||
| 39 | <p>Here is an example of a Code 128 barcode rendered with this module:</p> | ||||||||||
| 40 | |||||||||||
| 41 | <table style="border:0;margin:0;padding:0;border-spacing:0;" class="hbc"><tr style="border:0;margin:0;padding:0;"><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#000;color:inherit;text-align:center;" class="hbc_on"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#000;color:inherit;text-align:center;" class="hbc_on"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#fff;color:inherit;text-align:center;" class="hbc_off"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#000;color:inherit;text-align:center;" class="hbc_on"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#fff;color:inherit;text-align:center;" class="hbc_off"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#fff;color:inherit;text-align:center;" class="hbc_off"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#fff;color:inherit;text-align:center;" class="hbc_off"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#fff;color:inherit;text-align:center;" class="hbc_off"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#000;color:inherit;text-align:center;" class="hbc_on"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#fff;color:inherit;text-align:center;" class="hbc_off"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#fff;color:inherit;text-align:center;" class="hbc_off"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#000;color:inherit;text-align:center;" class="hbc_on"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#fff;color:inherit;text-align:center;" class="hbc_off"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#000;color:inherit;text-align:center;" class="hbc_on"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#000;color:inherit;text-align:center;" class="hbc_on"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#000;color:inherit;text-align:center;" class="hbc_on"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#fff;color:inherit;text-align:center;" class="hbc_off"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#000;color:inherit;text-align:center;" class="hbc_on"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#000;color:inherit;text-align:center;" class="hbc_on"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#fff;color:inherit;text-align:center;" class="hbc_off"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#fff;color:inherit;text-align:center;" class="hbc_off"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#fff;color:inherit;text-align:center;" class="hbc_off"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#000;color:inherit;text-align:center;" class="hbc_on"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#fff;color:inherit;text-align:center;" class="hbc_off"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#fff;color:inherit;text-align:center;" class="hbc_off"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#fff;color:inherit;text-align:center;" class="hbc_off"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#000;color:inherit;text-align:center;" class="hbc_on"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#000;color:inherit;text-align:center;" class="hbc_on"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#000;color:inherit;text-align:center;" class="hbc_on"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#fff;color:inherit;text-align:center;" class="hbc_off"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#000;color:inherit;text-align:center;" class="hbc_on"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#000;color:inherit;text-align:center;" class="hbc_on"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#fff;color:inherit;text-align:center;" class="hbc_off"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#000;color:inherit;text-align:center;" class="hbc_on"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#fff;color:inherit;text-align:center;" class="hbc_off"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#000;color:inherit;text-align:center;" class="hbc_on"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#000;color:inherit;text-align:center;" class="hbc_on"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#000;color:inherit;text-align:center;" class="hbc_on"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#fff;color:inherit;text-align:center;" class="hbc_off"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#fff;color:inherit;text-align:center;" class="hbc_off"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#fff;color:inherit;text-align:center;" class="hbc_off"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#000;color:inherit;text-align:center;" class="hbc_on"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#000;color:inherit;text-align:center;" class="hbc_on"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#fff;color:inherit;text-align:center;" class="hbc_off"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#000;color:inherit;text-align:center;" class="hbc_on"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#fff;color:inherit;text-align:center;" class="hbc_off"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#000;color:inherit;text-align:center;" class="hbc_on"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#000;color:inherit;text-align:center;" class="hbc_on"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#fff;color:inherit;text-align:center;" class="hbc_off"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#fff;color:inherit;text-align:center;" class="hbc_off"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#fff;color:inherit;text-align:center;" class="hbc_off"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#000;color:inherit;text-align:center;" class="hbc_on"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#000;color:inherit;text-align:center;" class="hbc_on"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#000;color:inherit;text-align:center;" class="hbc_on"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#fff;color:inherit;text-align:center;" class="hbc_off"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#000;color:inherit;text-align:center;" class="hbc_on"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#fff;color:inherit;text-align:center;" class="hbc_off"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#fff;color:inherit;text-align:center;" class="hbc_off"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#fff;color:inherit;text-align:center;" class="hbc_off"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#000;color:inherit;text-align:center;" class="hbc_on"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#000;color:inherit;text-align:center;" class="hbc_on"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#fff;color:inherit;text-align:center;" class="hbc_off"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#000;color:inherit;text-align:center;" class="hbc_on"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#fff;color:inherit;text-align:center;" class="hbc_off"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#fff;color:inherit;text-align:center;" class="hbc_off"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#fff;color:inherit;text-align:center;" class="hbc_off"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#000;color:inherit;text-align:center;" class="hbc_on"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#000;color:inherit;text-align:center;" class="hbc_on"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#000;color:inherit;text-align:center;" class="hbc_on"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#fff;color:inherit;text-align:center;" class="hbc_off"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#000;color:inherit;text-align:center;" class="hbc_on"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#000;color:inherit;text-align:center;" class="hbc_on"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#fff;color:inherit;text-align:center;" class="hbc_off"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#000;color:inherit;text-align:center;" class="hbc_on"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#fff;color:inherit;text-align:center;" class="hbc_off"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#fff;color:inherit;text-align:center;" class="hbc_off"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#fff;color:inherit;text-align:center;" class="hbc_off"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#000;color:inherit;text-align:center;" class="hbc_on"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#000;color:inherit;text-align:center;" class="hbc_on"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#fff;color:inherit;text-align:center;" class="hbc_off"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#000;color:inherit;text-align:center;" class="hbc_on"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#fff;color:inherit;text-align:center;" class="hbc_off"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#fff;color:inherit;text-align:center;" class="hbc_off"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#fff;color:inherit;text-align:center;" class="hbc_off"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#000;color:inherit;text-align:center;" class="hbc_on"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#000;color:inherit;text-align:center;" class="hbc_on"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#000;color:inherit;text-align:center;" class="hbc_on"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#fff;color:inherit;text-align:center;" class="hbc_off"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#000;color:inherit;text-align:center;" class="hbc_on"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#000;color:inherit;text-align:center;" class="hbc_on"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#fff;color:inherit;text-align:center;" class="hbc_off"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#fff;color:inherit;text-align:center;" class="hbc_off"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#fff;color:inherit;text-align:center;" class="hbc_off"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#000;color:inherit;text-align:center;" class="hbc_on"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#000;color:inherit;text-align:center;" class="hbc_on"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#000;color:inherit;text-align:center;" class="hbc_on"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#fff;color:inherit;text-align:center;" class="hbc_off"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#000;color:inherit;text-align:center;" class="hbc_on"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#fff;color:inherit;text-align:center;" class="hbc_off"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#000;color:inherit;text-align:center;" class="hbc_on"></td><td style="border:0;margin:0;padding:0;width:2px;height:100px;background-color:#000;color:inherit;text-align:center;" class="hbc_on"></td></tr><tr style="border:0;margin:0;padding:0;"><td style="border:0;margin:0;padding:0;width:auto;height:auto;background-color:#fff;color:inherit;text-align:center;" colspan="101">MONKEY</td></tr></table> | ||||||||||
| 42 | |||||||||||
| 43 | =end html | ||||||||||
| 44 | |||||||||||
| 45 | This B<requires> L<Barcode::Code128>. You may also use the | ||||||||||
| 46 | L<character constants|Barcode::Code128/EXPORTS> from this module in your text. | ||||||||||
| 47 | Be sure to provide their full package name. | ||||||||||
| 48 | For example: | ||||||||||
| 49 | |||||||||||
| 50 | my $text = Barcode::Code128::FNC1 . '00000123455555555558'; | ||||||||||
| 51 | HTML::Barcode::Code128->new(text => $text)->render; | ||||||||||
| 52 | |||||||||||
| 53 | You can read more about Code 128 online (e.g. L<http://en.wikipedia.org/wiki/Code_128>). | ||||||||||
| 54 | |||||||||||
| 55 | =head1 METHODS | ||||||||||
| 56 | |||||||||||
| 57 | =head2 new (%attributes) | ||||||||||
| 58 | |||||||||||
| 59 | Instantiate a new HTML::Barcode::Code128 object. The C<%attributes> hash | ||||||||||
| 60 | requires the L</text> attribute, and can take any of the other | ||||||||||
| 61 | L<attributes|/ATTRIBUTES> listed below. | ||||||||||
| 62 | |||||||||||
| 63 | =head2 render | ||||||||||
| 64 | |||||||||||
| 65 | This is a convenience routine which returns C<< <style>...</style> >> tags | ||||||||||
| 66 | and the rendered barcode. | ||||||||||
| 67 | |||||||||||
| 68 | If you are printing multiple barcodes or want to ensure your C<style> tags | ||||||||||
| 69 | are in your HTML headers, then you probably want to output the barcode | ||||||||||
| 70 | and style separately with L</render_barcode> and | ||||||||||
| 71 | L</css>. | ||||||||||
| 72 | |||||||||||
| 73 | =head2 render_barcode | ||||||||||
| 74 | |||||||||||
| 75 | Returns only the rendered barcode. You will need to provide stylesheets | ||||||||||
| 76 | separately, either writing them yourself or using the output of L</css>. | ||||||||||
| 77 | |||||||||||
| 78 | =head2 css | ||||||||||
| 79 | |||||||||||
| 80 | Returns CSS needed to properly display your rendered barcode. This is | ||||||||||
| 81 | only necessary if you are using L</render_barcode> instead of the | ||||||||||
| 82 | easier L</render> method. | ||||||||||
| 83 | |||||||||||
| 84 | =head1 ATTRIBUTES | ||||||||||
| 85 | |||||||||||
| 86 | These attributes can be passed to L<new|/"new (%attributes)">, or used | ||||||||||
| 87 | as accessors. | ||||||||||
| 88 | |||||||||||
| 89 | =head2 text | ||||||||||
| 90 | |||||||||||
| 91 | B<Required> - The information to put into the barcode. | ||||||||||
| 92 | |||||||||||
| 93 | =head2 foreground_color | ||||||||||
| 94 | |||||||||||
| 95 | A CSS color value (e.g. '#000' or 'black') for the foreground. Default is '#000'. | ||||||||||
| 96 | |||||||||||
| 97 | =head2 background_color | ||||||||||
| 98 | |||||||||||
| 99 | A CSS color value background. Default is '#fff'. | ||||||||||
| 100 | |||||||||||
| 101 | =head2 bar_width | ||||||||||
| 102 | |||||||||||
| 103 | A CSS value for the width of an individual bar. Default is '2px'. | ||||||||||
| 104 | |||||||||||
| 105 | =head2 bar_height | ||||||||||
| 106 | |||||||||||
| 107 | A CSS value for the height of an individual bar. Default is '100px'. | ||||||||||
| 108 | |||||||||||
| 109 | =head2 show_text | ||||||||||
| 110 | |||||||||||
| 111 | Boolean, default true. Indicates whether or not to render the text | ||||||||||
| 112 | below the barcode. | ||||||||||
| 113 | |||||||||||
| 114 | =head2 css_class | ||||||||||
| 115 | |||||||||||
| 116 | The value for the C<class> attribute applied to any container tags | ||||||||||
| 117 | in the HTML (e.g. C<table> or C<div>). | ||||||||||
| 118 | C<td> tags within the table will have either css_class_on or css_class_off | ||||||||||
| 119 | classes applied to them. | ||||||||||
| 120 | |||||||||||
| 121 | For example, if css_class is "barcode", you will get C<< <table class="barcode"> >> and its cells will be either C<< <td class="barcode_on"> >> or | ||||||||||
| 122 | C<< <td class="barcode_off"> >>. | ||||||||||
| 123 | |||||||||||
| 124 | =head2 embed_style | ||||||||||
| 125 | |||||||||||
| 126 | Rather than rendering CSS stylesheets, embed the style information | ||||||||||
| 127 | in HTML C<style> attributes. You should not use this option without | ||||||||||
| 128 | good reason, as it greatly increases the size of the generated markup, | ||||||||||
| 129 | and makes it impossible to override with stylesheets. | ||||||||||
| 130 | |||||||||||
| 131 | =head1 AUTHOR | ||||||||||
| 132 | |||||||||||
| 133 | Mark A. Stratman, C<< <stratman@gmail.com> >> | ||||||||||
| 134 | |||||||||||
| 135 | =head1 SOURCE REPOSITORY | ||||||||||
| 136 | |||||||||||
| 137 | L<http://github.com/mstratman/HTML-Barcode-Code128> | ||||||||||
| 138 | |||||||||||
| 139 | =head1 SEE ALSO | ||||||||||
| 140 | |||||||||||
| 141 | L<Barcode::Code128> | ||||||||||
| 142 | |||||||||||
| 143 | =head1 LICENSE AND COPYRIGHT | ||||||||||
| 144 | |||||||||||
| 145 | Copyright 2011 Mark A. Stratman. | ||||||||||
| 146 | |||||||||||
| 147 | This program is free software; you can redistribute it and/or modify it | ||||||||||
| 148 | under the terms of either: the GNU General Public License as published | ||||||||||
| 149 | by the Free Software Foundation; or the Artistic License. | ||||||||||
| 150 | |||||||||||
| 151 | See http://dev.perl.org/licenses/ for more information. | ||||||||||
| 152 | |||||||||||
| 153 | |||||||||||
| 154 | =cut | ||||||||||
| 155 | |||||||||||
| 156 | |||||||||||
| 157 | 2 | ▶ | no Any::Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 158 | 2 | 1; | |||||||||