Acme/MetaSyntactic/List.pm

filter: Statementstmt 96.2% 77 / 80 Branchbran 83.3% 10 / 12 Conditioncond 81.8% 9 / 11 MC/DCmcdc 42.8% 3 / 7 Subroutinesub 100% 17 / 17 Podpod 100% 4 / 4 totaltotal 91.6% 120 / 131 CC 11 SCAR 12.2
CC
11
Cov
93%
name
8.1
init
3.0
theme
2.0
CRAP 3.4
« Acme/MetaSyntactic/MultiList.pm ↑ Summary Acme/MetaSyntactic.pm »
1 package Acme::MetaSyntactic::List;
2 23 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 23 ▶use Acme::MetaSyntactic (); # do not export metaname and friends
Subroutine BEGIN: called CC=1 SCAR=0.0
4 23 ▶use Acme::MetaSyntactic::RemoteList;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 23 ▶use List::Util qw( shuffle );
Subroutine BEGIN: called CC=1 SCAR=0.0
6 23 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 23 our @ISA = qw( Acme::MetaSyntactic::RemoteList );
9 23 our $VERSION = '1.001';
10  
11 sub init {
12 23 ▶ my ($self, $data) = @_;
Subroutine init: called CC=3 SCAR=11.0
Pod documented
13 23 my $class = caller(0);
14  
15 23 ▶ $data ||= Acme::MetaSyntactic->load_data($class);
Condition66%2/3
$data ||= "Acme::MetaSyntactic"->load_data($class)
l!l&&r!l&&!r
4190
MC/DC0%0/2
$data ||= "Acme::MetaSyntactic"->load_data($class)
$data "Acme::MetaSyntactic"->load_data($class)
Truth table66%2/3
A ||= B
A= $dataB= "Acme::MetaSyntactic"->load_data($class)
ABresult
1X1
011
000
16 23 ▶ croak "The optional argument to init() must be a hash reference"
Branch: 1 branch
BranchTrueFalseTotal
if ref $data ne "HASH" 0 23 23
17 if ref $data ne 'HASH';
18  
19 23 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
20 23 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 23 ${"$class\::Theme"} = ( split /::/, $class )[-1];
22 23 @{"$class\::List"} = do { my %seen;
23 23 grep !$seen{$_}++, split /\s+/, $data->{names} };
24 23 *{"$class\::import"} = sub {
25 13 ▶ my $callpkg = caller(0);
Subroutine __ANON__: called CC=1 SCAR=0.0
26 13 my $theme = ${"$class\::Theme"};
27 13 my $meta = $class->new();
28 13 ▶ *{"$callpkg\::meta$theme"} = sub { $meta->name(@_) };
Subroutine __ANON__: called CC=1 SCAR=0.0
29 23 };
30 23 ${"$class\::meta"} = $class->new();
31 }
32  
33 sub name {
34 37 ▶ my ( $self, $count ) = @_;
Subroutine name: called CC=8 SCAR=20.9
Pod documented
35 37 my $class = ref $self;
36  
37 37 ▶ if( ! $class ) { # called as a class method!
Branch: 1 branch
BranchTrueFalseTotal
unless ($class) 0 37 37
38 0 $class = $self;
39 23 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
40 0 $self = ${"$class\::meta"};
41 }
42  
43 37 ▶ if( defined $count && $count == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $count and $count == 0) 11 26 37
Condition100%3/3
defined $count and $count == 0
!ll&&!rl&&r
91711
MC/DC100%2/2
defined $count and $count == 0
defined $count $count == 0
Truth table100%3/3
A and B
A= defined $countB= $count == 0
ABresult
0X0
100
111
44 23 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
45 return
46 11 ▶ wantarray ? shuffle @{"$class\::List"} : scalar @{"$class\::List"};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 10 1 11
47 }
48  
49 26 ▶ $count ||= 1;
Condition100%2/2
$count ||= 1
l!l
179
MC/DC100%1/1
$count ||= 1
$count
Truth table100%2/2
A
A= $count
Aresult
11
00
50 26 my $list = $self->{cache};
51 {
52 23 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
53 26 ▶ if (@{"$class\::List"}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{"${class}::List";}) 24 2 26
54 24 ▶ push @$list, shuffle @{"$class\::List"} while @$list < $count;
Branch: 1 branch
BranchTrueFalseTotal
@$list < $count and do { push @$list, &shuffle(@{"${class}::List";}) } 22 24 46
55 }
56 }
57 26 splice( @$list, 0, $count );
58 }
59  
60 sub new {
61 65 ▶ my $class = shift;
Subroutine new: called CC=1 SCAR=0.0
Pod documented
62  
63 65 bless { cache => [] }, $class;
64 }
65  
66 sub theme {
67 2 ▶ my $class = ref $_[0] || $_[0];
Subroutine theme: called CC=2 SCAR=7.0
Pod documented
Condition66%2/3
ref $_[0] || $_[0]
l!l&&r!l&&!r
110
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0] $_[0]
Truth table66%2/3
A || B
A= ref $_[0]B= $_[0]
ABresult
1X1
011
000
68 23 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
69 2 return ${"$class\::Theme"};
70 }
71  
72 23 1;
73  
74 __END__
« Acme/MetaSyntactic/MultiList.pm ↑ Summary Acme/MetaSyntactic.pm »