File Coverage

blib/lib/Spp/Core.pm
Criterion Covered Total %
statement 30 42 71.4
branch 3 10 30.0
condition 2 3 66.6
subroutine 9 12 75.0
pod 0 8 0.0
total 44 75 58.6


line stmt bran cond sub pod time code
1             package Spp::Core;
2              
3 2     2   25 use 5.012;
  2         6  
4 2     2   8 no warnings "experimental";
  2         4  
  2         49  
5              
6 2     2   11 use Exporter;
  2         3  
  2         108  
7             our @ISA = qw(Exporter);
8             our @EXPORT = qw(match get_rept_time is_atom_name
9             is_tillnot is_look is_rept is_sym is_atom_str);
10              
11 2     2   9 use Spp::Builtin qw(is_atom len rest to_json);
  2         3  
  2         620  
12              
13             sub match {
14 0     0 0 0 my $atoms = shift;
15 0 0       0 if (len($atoms) > 1) {
16 0         0 return $atoms->[0], rest($atoms);
17             }
18 0 0       0 if (len($atoms) == 1) {
19 0         0 return $atoms->[0], [];
20             }
21 0         0 say to_json($atoms);
22 0         0 say "match element less 2"; exit();
  0         0  
23             }
24              
25             sub get_rept_time {
26 99     99 0 138 my $rept = shift;
27 99         122 given ($rept) {
28 99         141 when ('?') { return (0, 1) }
  1         4  
29 98         121 when ('*') { return (0, -1) }
  3         12  
30 95         124 default { return (1, -1) }
  95         215  
31             }
32             }
33              
34             sub is_atom_name {
35 14     14 0 27 my ($atom, $name) = @_;
36 14   66     30 return (is_atom($atom) and $atom->[0] eq $name);
37             }
38              
39             sub is_tillnot {
40 7     7 0 18 my $s = shift;
41 7 50       16 if (is_atom($s)) {
42 7 50       16 return 1 if $s->[0] eq 'Till';
43 7 50       21 return 1 if $s->[0] eq 'Not';
44             }
45 7         20 return 0;
46             }
47              
48             sub is_rept {
49 7     7 0 11 my $atom = shift;
50 7         16 return is_atom_name($atom, '_rept')
51             }
52              
53             sub is_look {
54 7     7 0 13 my $atom = shift;
55 7         19 return is_atom_name($atom, '_look')
56             }
57              
58             sub is_sym {
59 0     0 0   my $atom = shift;
60 0           return is_atom_name($atom, 'Sym')
61             }
62              
63             sub is_atom_str {
64 0     0 0   my $atom = shift;
65 0           return is_atom_name($atom, 'Str')
66             }
67              
68             1;