File Coverage

blib/lib/Term/QRCode.pm
Criterion Covered Total %
statement 13 15 86.6
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 18 20 90.0


line stmt bran cond sub pod time code
1             package Term::QRCode;
2 1     1   4 use strict;
  1         1  
  1         31  
3 1     1   4 use warnings;
  1         1  
  1         32  
4             our $VERSION = '0.01';
5              
6 1     1   4 use Carp;
  1         1  
  1         72  
7 1     1   14512 use Term::ANSIColor;
  1         8518  
  1         87  
8 1     1   475 use Text::QRCode;
  0            
  0            
9              
10             sub new {
11             my($class, %args) = @_;
12             bless {
13             text_qrcode => Text::QRCode->new(delete $args{params} || +{}),
14             white_text => colored(' ', delete $args{white} || 'on_white'),
15             black_text => colored(' ', delete $args{black} || 'on_black'),
16             %args,
17             }, $class;
18             }
19              
20             sub plot {
21             my($self, $text) = @_;
22             croak 'Not enough arguments for plot()' unless $text;
23              
24             my $arref = $self->{text_qrcode}->plot($text);
25             $self->_add_blank($arref);
26             $self->{stdoutbuf} = join "\n", map { join '', map { $_ eq '*' ? $self->{black_text} : $self->{white_text} } @$_ } @$arref;
27             }
28              
29             sub _add_blank {
30             my($self, $ref) = @_;
31             unshift @$_, ' ' and push @$_, ' ' for @$ref;
32             unshift @$ref, [(' ') x scalar @{$ref->[0]}];
33             push @$ref, [(' ') x scalar @{$ref->[0]}];
34             }
35              
36             1;
37             __END__