File Coverage

blib/lib/Math/Logic/Ternary/Calculator.pm
Criterion Covered Total %
statement 28 31 90.3
branch 8 10 80.0
condition 3 3 100.0
subroutine 6 6 100.0
pod 1 1 100.0
total 46 51 90.2


line stmt bran cond sub pod time code
1             # Copyright (c) 2012-2017 Martin Becker, Blaubeuren. All rights reserved.
2             # This package is free software; you can redistribute it and/or modify it
3             # under the same terms as Perl itself.
4              
5             package Math::Logic::Ternary::Calculator;
6              
7 1     1   46909 use 5.008;
  1         4  
8 1     1   5 use strict;
  1         1  
  1         17  
9 1     1   3 use warnings;
  1         2  
  1         27  
10 1     1   255 use Math::Logic::Ternary::Calculator::State;
  1         3  
  1         26  
11 1     1   284 use Math::Logic::Ternary::Calculator::Session;
  1         3  
  1         210  
12              
13             require Exporter;
14              
15             our $VERSION = '0.004';
16             our @ISA = qw(Exporter);
17             our @EXPORT = qw(tcalc);
18              
19             our $DEFAULT_WORD_SIZE = 27;
20              
21             sub tcalc {
22 4     4 1 3911 my ($size, $mode) = @_;
23 4 100       10 if (!defined $size) {
24 1         2 $size = $DEFAULT_WORD_SIZE;
25             }
26 4 100       9 if (!defined $mode) {
27 3         5 $mode = 0;
28             }
29 4 50 100     13 if (2 < @_ || grep { defined $_ and !/^\d+\z/ } $size, $mode) {
  6 100       38  
30 2         10 die "usage: tcalc [word_size [mode]]\n";
31             }
32 2         4 my $state = eval {
33 2         12 Math::Logic::Ternary::Calculator::State->new($size, $mode)
34             };
35 2 50       4 if (!defined $state) {
36 0         0 my $msg = $@;
37 0         0 $msg =~ s/ at .*? line \d+\.$//;
38 0         0 die $msg;
39             }
40 2         9 my $session = Math::Logic::Ternary::Calculator::Session->new($state);
41 2         7 $session->run;
42 2         22 return;
43             }
44              
45             1;
46             __END__