File Coverage

blib/lib/Acme/Lelek.pm
Criterion Covered Total %
statement 24 24 100.0
branch n/a
condition n/a
subroutine 10 10 100.0
pod 2 2 100.0
total 36 36 100.0


line stmt bran cond sub pod time code
1 2     2   58180 use strict;
  2         7  
  2         84  
2 2     2   12 use warnings;
  2         4  
  2         113  
3              
4             package Acme::Lelek;
5             {
6             $Acme::Lelek::VERSION = '1.003';
7             }
8              
9             # ABSTRACT: encode/decode text to lelek code.
10 2     2   4610 use autobox::Core;
  2         73730  
  2         15  
11 2     2   3166 use Convert::BaseN;
  2         15135  
  2         3143  
12 2     2   2377 use Const::Fast;
  2         7866  
  2         15  
13 2     2   4573 use Moo;
  2         49492  
  2         13  
14              
15             const my $lek_re => qr/^lek$/i;
16             const my @leks => qw(lek leK lEk Lek lEK LeK LEk LEK);
17             const my %octals => map { $leks[$_] => $_ } 0 .. 7;
18              
19             has base8 => (
20             is => 'ro',
21             required => 1,
22             default => sub {
23             Convert::BaseN->new( base => 8 );
24             }
25             );
26              
27             sub encode {
28 1     1 1 100 my ( $self, $msg ) = @_;
29              
30             $self->base8->encode($msg)->split('')->grep(qr/[0-7]/)
31 1     8   14 ->map( sub { $leks[$_] } )->unshift('AH Le')->join(' ');
  8         575  
32             }
33              
34             sub decode {
35 2     2 1 1604 my ( $self, $msg ) = @_;
36              
37             $self->base8->decode(
38             $msg->split(qr/\s+/)->grep($lek_re)->map(
39             sub {
40 16     16   200 $octals{$_};
41             }
42 2         23 )->join('')
43             );
44             }
45              
46             1;
47              
48             __END__