Acme/MetaSyntactic/MultiList.pm

filter: Statementstmt 96.8% 123 / 127 Branchbran 92.8% 26 / 28 Conditioncond 80.9% 17 / 21 MC/DCmcdc 46.1% 6 / 13 Subroutinesub 100% 23 / 23 Podpod 100% 7 / 7 totaltotal 92.2% 202 / 219 CC 23 SCAR 14.7
CC
23
Cov
94%
init
9.0
name
8.3
new
4.0
CRAP 4.3
« Acme/MetaSyntactic/RemoteList.pm ↑ Summary Acme/MetaSyntactic/List.pm »
1 package Acme::MetaSyntactic::MultiList;
2 27 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 27 ▶use Acme::MetaSyntactic (); # do not export metaname and friends
Subroutine BEGIN: called CC=1 SCAR=0.0
4 27 ▶use Acme::MetaSyntactic::RemoteList;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 27 ▶use List::Util qw( shuffle );
Subroutine BEGIN: called CC=1 SCAR=0.0
6 27 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 27 our @ISA = qw( Acme::MetaSyntactic::RemoteList );
9 27 our $VERSION = '1.000';
10  
11 sub init {
12 25 ▶ my ($self, $data) = @_;
Subroutine init: called CC=9 SCAR=22.0
Pod documented
13 25 my $class = caller(0);
14  
15 25 ▶ $data ||= Acme::MetaSyntactic->load_data($class);
Condition66%2/3
$data ||= "Acme::MetaSyntactic"->load_data($class)
l!l&&r!l&&!r
1240
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 27 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 # note: variables mentioned twice to avoid a warning
19  
20 25 ▶ my $sep = ${"$class\::Separator"} = ${"$class\::Separator"} ||= '/';
Condition100%2/2
${"${class}::Separator";} ||= "/"
l!l
232
MC/DC100%1/1
${"${class}::Separator";} ||= "/"
${"${class}::Separator";}
Truth table100%2/2
A
A= ${"${class}::Separator";}
Aresult
11
00
21 25 my $tail = qr/$sep?[^$sep]*$/;
22  
23 # compute all categories
24 25 my @categories = ( [ $data->{names}, '' ] );
25 25 ▶ while ( my ( $h, $k ) = @{ shift @categories or []} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (() = @{shift @categories or [];}) 141 25 166
shift @categories or [] 25 141 166
26 141 ▶ if ( ref $h eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $h eq 'HASH') { } 30 111 141
27 push @categories,
28 30 ▶ map { [ $h->{$_}, ( $k ? "$k$sep$_" : $_ ) ] } keys %$h;
Branch: 1 branch
BranchTrueFalseTotal
$k ? : 9 107 116
29 }
30 else { # leaf
31 111 my @items = split /\s+/, $h;
32 111 ▶ while ($k) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k) 121 111 232
33 121 push @{ ${"$class\::MultiList"}{$k} }, @items;
34 121 $k =~ s!$tail!!;
35 }
36 }
37 }
38  
39 25 ▶ ${"$class\::Default"} = ${"$class\::Default"} = $data->{default} || ':all';
Condition50%1/2
$data->{'default'} || ':all'
l!l
250
MC/DC0%0/1
$data->{'default'} || ':all'
$data->{'default'}
Truth table50%1/2
A
A= $data->{'default'}
Aresult
11
00
40 25 ${"$class\::Theme"} = ${"$class\::Theme"} = ( split /::/, $class )[-1];
41  
42 25 *{"$class\::import"} = sub {
43 13 ▶ my $callpkg = caller(0);
Subroutine __ANON__: called CC=1 SCAR=0.0
44 13 my $theme = ${"$class\::Theme"};
45 13 my $meta = $class->new;
46 13 ▶ *{"$callpkg\::meta$theme"} = sub { $meta->name(@_) };
Subroutine __ANON__: called CC=1 SCAR=0.0
47 25 };
48  
49 25 ${"$class\::meta"} = ${"$class\::meta"} = $class->new();
50 }
51  
52 sub name {
53 104 ▶ my ( $self, $count ) = @_;
Subroutine name: called CC=8 SCAR=21.1
Pod documented
54 104 my $class = ref $self;
55  
56 104 ▶ if ( !$class ) { # called as a class method!
Branch: 1 branch
BranchTrueFalseTotal
unless ($class) 0 104 104
57 0 $class = $self;
58 27 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
59 0 $self = ${"$class\::meta"};
60 }
61  
62 104 ▶ if ( defined $count && $count == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $count and $count == 0) 45 59 104
Condition100%3/3
defined $count and $count == 0
!ll&&!rl&&r
322745
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
63 27 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
64 return wantarray
65 45 ? shuffle @{ $self->{base} }
66 45 ▶ : scalar @{ $self->{base} };
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 45 0 45
67 }
68  
69 59 ▶ $count ||= 1;
Condition100%2/2
$count ||= 1
l!l
2732
MC/DC100%1/1
$count ||= 1
$count
Truth table100%2/2
A
A= $count
Aresult
11
00
70 59 my $list = $self->{cache};
71 59 ▶ if ( @{ $self->{base} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{"base"};}) 57 2 59
72 57 ▶ push @$list, shuffle @{ $self->{base} } while @$list < $count;
Branch: 1 branch
BranchTrueFalseTotal
@$list < $count and do { push @$list, &shuffle(@{$$self{"base"};}) } 60 57 117
73 }
74 59 splice( @$list, 0, $count );
75 }
76  
77 sub new {
78 18 ▶ my $class = shift;
Subroutine new: called CC=4 SCAR=13.9
Pod documented
79  
80 27 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
81 18 my $self = bless { @_, cache => [] }, $class;
82  
83 # compute some defaults
84 18 ▶ $self->{category} ||= ${"$class\::Default"};
Condition66%2/3
$self->{"category"} ||= ${"${class}::Default";}
l!l&&r!l&&!r
1440
MC/DC0%0/2
$self->{"category"} ||= ${"${class}::Default";}
$self->{"category"} ${"${class}::Default";}
Truth table66%2/3
A ||= B
A= $self->{"category"}B= ${"${class}::Default";}
ABresult
1X1
011
000
85  
86 # fall back to last resort (FIXME should we carp()?)
87 1 $self->{category} = ${"$class\::Default"}
88 if $self->{category} ne ':all'
89 18 ▶ && !exists ${"$class\::MultiList"}{ $self->{category} };
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"category"} ne ":all" and not exists ${"${class}::MultiList";}{$self->{"category"}} 1 17 18
Condition100%3/3
$self->{"category"} ne ":all" and not exists ${"${class}::MultiList";}{$self->{"category"}}
!ll&&!rl&&r
1161
MC/DC100%2/2
$self->{"category"} ne ":all" and not exists ${"${class}::MultiList";}{$self->{"category"}}
$self->{"category"} ne ":all" not exists ${"${class}::MultiList";}{$self->{"category"}}
Truth table100%3/3
A and not(B)
A= $self->{"category"} ne ":all"B= not exists ${"${class}::MultiList";}{$self->{"category"}}
ABresult
0X0
100
111
90  
91 18 $self->_compute_base();
92 18 return $self;
93 }
94  
95 sub _compute_base {
96 113 ▶ my ($self) = @_;
Subroutine _compute_base: called CC=2 SCAR=6.9
97 113 my $class = ref $self;
98  
99 # compute the base list for this category
100 27 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
101 113 my %seen;
102 $self->{base} = [
103 1100 grep { !$seen{$_}++ }
104 127 ▶ map { @{ ${"$class\::MultiList"}{$_} } }
Branch: 1 branch
BranchTrueFalseTotal
$self->{'category'} eq ':all' ? : 2 111 113
105 $self->{category} eq ':all'
106 2 ? ( keys %{"$class\::MultiList"} )
107 : ( $self->{category} )
108 113 ];
109 113 return;
110 }
111  
112 32 ▶sub category { $_[0]->{category} }
Subroutine category: called CC=1 SCAR=0.0
Pod documented
113  
114 sub categories {
115 7 ▶ my $class = shift;
Subroutine categories: called CC=2 SCAR=6.9
Pod documented
116 7 ▶ $class = ref $class if ref $class;
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 2 5 7
117  
118 27 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
119 7 return keys %{"$class\::MultiList"};
120 }
121  
122 sub has_category {
123 6 ▶ my ($class, $category) = @_;
Subroutine has_category: called CC=2 SCAR=6.9
Pod documented
124 6 ▶ $class = ref $class if ref $class;
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 3 3 6
125  
126 27 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
127 6 return exists ${"$class\::MultiList"}{$category};
128 }
129  
130 sub theme {
131 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
132 27 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
133 2 return ${"$class\::Theme"};
134 }
135  
136 27 1;
137  
138 __END__
« Acme/MetaSyntactic/RemoteList.pm ↑ Summary Acme/MetaSyntactic/List.pm »