| 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)
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)
| |||||||||||||||||||||||||||||
| 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";} ||= "/"
MC/DC100%1/1
${"${class}::Separator";} ||= "/"
${"${class}::Separator";}
Truth table100%2/2
A
A= ${"${class}::Separator";}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 26 | 141 | ▶ | if ( ref $h eq 'HASH' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | push @categories, | ||||||||||||||||||||||||||||
| 28 | 30 | ▶ | map { [ $h->{$_}, ( $k ? "$k$sep$_" : $_ ) ] } keys %$h; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | else { # leaf | ||||||||||||||||||||||||||||
| 31 | 111 | my @items = split /\s+/, $h; | |||||||||||||||||||||||||||
| 32 | 111 | ▶ | while ($k) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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'
MC/DC0%0/1
$data->{'default'} || ':all'
$data->{'default'}
Truth table50%1/2
A
A= $data->{'default'}
| |||||||||||||||||||||||||||||
| 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 | 105 | ▶ | my ( $self, $count ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
name: called CC=8 SCAR=21.1
Pod
documented
| |||||||||||||||||||||||||||||
| 54 | 105 | my $class = ref $self; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 105 | ▶ | if ( !$class ) { # called as a class method! | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | 105 | ▶ | if ( defined $count && $count == 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $count and $count == 0
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
| |||||||||||||||||||||||||||||
| 63 | 27 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 64 | return wantarray | ||||||||||||||||||||||||||||
| 65 | 46 | ? shuffle @{ $self->{base} } | |||||||||||||||||||||||||||
| 66 | 46 | ▶ | : scalar @{ $self->{base} }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 59 | ▶ | $count ||= 1; | ||||||||||||||||||||||||||
|
Condition100%2/2
$count ||= 1
MC/DC100%1/1
$count ||= 1
$count
Truth table100%2/2
A
A= $count
| |||||||||||||||||||||||||||||
| 70 | 59 | my $list = $self->{cache}; | |||||||||||||||||||||||||||
| 71 | 59 | ▶ | if ( @{ $self->{base} } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 57 | ▶ | push @$list, shuffle @{ $self->{base} } while @$list < $count; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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";}
MC/DC0%0/2
$self->{"category"} ||= ${"${class}::Default";}
$self->{"category"}
${"${class}::Default";}
Truth table66%2/3
A ||= B
A= $self->{"category"}B= ${"${class}::Default";}
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
$self->{"category"} ne ":all" and not exists ${"${class}::MultiList";}{$self->{"category"}}
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"}}
| |||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 18 | $self->_compute_base(); | |||||||||||||||||||||||||||
| 92 | 18 | return $self; | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | sub _compute_base { | ||||||||||||||||||||||||||||
| 96 | 114 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_compute_base: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 97 | 114 | 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 | 114 | my %seen; | |||||||||||||||||||||||||||
| 102 | $self->{base} = [ | ||||||||||||||||||||||||||||
| 103 | 1115 | grep { !$seen{$_}++ } | |||||||||||||||||||||||||||
| 104 | 128 | ▶ | map { @{ ${"$class\::MultiList"}{$_} } } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | $self->{category} eq ':all' | ||||||||||||||||||||||||||||
| 106 | 2 | ? ( keys %{"$class\::MultiList"} ) | |||||||||||||||||||||||||||
| 107 | : ( $self->{category} ) | ||||||||||||||||||||||||||||
| 108 | 114 | ]; | |||||||||||||||||||||||||||
| 109 | 114 | 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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]
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0]
$_[0]
Truth table66%2/3
A || B
A= ref $_[0]B= $_[0]
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||