Chart/GGPlot/Guides.pm

filter: Statementstmt 23.0% 23 / 100 Branchbran 0.0% 0 / 48 Conditioncond 0.0% 0 / 21 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 38.4% 5 / 13 Podpod 25.0% 1 / 4 totaltotal 14.5% 29 / 199 CC 33 SCAR 49.7
CC
33
Cov
14%
build
342.0
_validate_guide
20.0
_matched_aes
20.0
CRAP 143.6
« Chart/GGPlot/Util/Stats.pm ↑ Summary Chart/GGPlot/Stat/Smooth.pm »
1 package Chart::GGPlot::Guides;
2  
3 # ABSTRACT: The container of guides
4  
5 2 ▶use Chart::GGPlot::Class qw(:pdl);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 our $VERSION = '0.002003'; # VERSION
9  
10 2 ▶use List::AllUtils qw(uniq);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Module::Load;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 6 ▶has _guides => (is => 'ro', default => sub { {} });
Subroutine __ANON__: called CC=1 SCAR=0.0
14  
15  
16 0 ▶my $defined_or = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
17 0 my ( $obj, $attr, $or ) = @_;
18  
19 # Have to make $or a coderef. Too bad Perl 5 does not support macros.
20 0 ▶ unless ( defined $obj->{$attr} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $obj->{$attr}) 0 0 0
21 0 $obj->{$attr} = $or->();
22 }
23 2 };
24  
25 # Train each scale in scales and generate the definition of guide.
26 0 ▶method build ($scales, :$layers, :$labels, :$default_mapping=undef, %rest) {
Subroutine build: not called CC=18 SCAR=58.3
Pod documented
Branch: 4 branches
BranchTrueFalseTotal
@_ < 6 and Function::Parameters::_croak('Too few arguments for method build (expected 6, got ' . @_ . ')') 0 0 0
@_ > 2 and (@_ - 2) % 2 and Function::Parameters::_croak("Odd number of paired arguments for method build") 0 0 0
exists $rest{'layers'} ? : 0 0 0
exists $rest{'labels'} ? : 0 0 0
Condition0%0/3
@_ > 2 and (@_ - 2) % 2
!ll&&!rl&&r
000
MC/DC0%0/2
@_ > 2 and (@_ - 2) % 2
@_ > 2 (@_ - 2) % 2
Truth table0%0/3
A and B
A= @_ > 2B= (@_ - 2) % 2
ABresult
0X0
100
111
27 0 my @gdefs;
28 0 for my $scale ($scales->scales->flatten) {
29 0 for my $output ( $scale->aesthetics->flatten ) {
30 0 ▶ my $guide = $self->get_guide($output) // $scale->guide;
Condition0%0/3
$self->get_guide($output) // $scale->guide
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->get_guide($output) // $scale->guide
$self->get_guide($output) $scale->guide
Truth table0%0/3
A // B
A= $self->get_guide($output)B= $scale->guide
ABresult
1X1
011
000
31  
32 0 ▶ next unless (defined $guide and $guide ne 'none');
Branch: 1 branch
BranchTrueFalseTotal
unless defined $guide and $guide ne "none" 0 0 0
Condition0%0/3
defined $guide and $guide ne "none"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $guide and $guide ne "none"
defined $guide $guide ne "none"
Truth table0%0/3
A and B
A= defined $guideB= $guide ne "none"
ABresult
0X0
100
111
33  
34 # Check the validity of guide.
35 # If guide is a string, then find the guide object.
36 0 $guide = $self->_validate_guide($guide);
37  
38 # Check the consistency of the guide and scale.
39 0 my $guide_available_aes = $guide->available_aes;
40 0 ▶ if ( defined $guide_available_aes
Branch: 1 branch
BranchTrueFalseTotal
if (defined $guide_available_aes and $guide_available_aes->intersect($scale->aesthetics)->length == 0) 0 0 0
Condition0%0/3
defined $guide_available_aes and $guide_available_aes->intersect($scale->aesthetics)->length == 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $guide_available_aes and $guide_available_aes->intersect($scale->aesthetics)->length == 0
defined $guide_available_aes $guide_available_aes->intersect($scale->aesthetics)->length == 0
Truth table0%0/3
A and B
A= defined $guide_available_aesB= $guide_available_aes->intersect($scale->aesthetics)->length == 0
ABresult
0X0
100
111
41 and $guide_available_aes->intersect( $scale->aesthetics )
42 ->length == 0 )
43 {
44 die sprintf( "Guide %s cannot be used for %s.",
45 0 $guide, join( ', ', @{ $scale->aesthetics } ) );
46 }
47  
48 0 ▶ unless (defined $guide->title) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $guide->title) 0 0 0
49 0 ▶ $guide->set( 'title',
Condition0%0/3
$scale->name // $labels->at($output)
l!l&&r!l&&!r
000
MC/DC0%0/2
$scale->name // $labels->at($output)
$scale->name $labels->at($output)
Truth table0%0/3
A // B
A= $scale->nameB= $labels->at($output)
ABresult
1X1
011
000
50 $scale->make_title( $scale->name // $labels->at($output) )
51 );
52 }
53  
54 0 $guide = $guide->train($scale, $output);
55 0 ▶ next unless defined $guide;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $guide 0 0 0
56  
57 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (&List::AllUtils::none(sub { my $matched = $self->_matched_aes($_, $guide, $default_mapping); my $show_legend = $_->show_legend; $matched->length > 0 and !defined($show_legend) || $show_legend; } , @$layers)) 0 0 0
58 0 ▶ List::AllUtils::none {
Subroutine __ANON__: not called CC=3 SCAR=24.8
59 0 my $matched =
60 $self->_matched_aes( $_, $guide, $default_mapping );
61 0 my $show_legend = $_->show_legend;
62 0 ▶ ( $matched->length > 0
Branch: 1 branch
BranchTrueFalseTotal
$matched->length > 0 and !defined($show_legend) || $show_legend 0 0 0
Condition0%0/6
$matched->length > 0 && (!defined($show_legend) || $show_legend)
!ll&&!rl&&r
000
not defined $show_legend or $show_legend
l!l&&r!l&&!r
000
MC/DC0%0/3
$matched->length > 0 && (!defined($show_legend) || $show_legend)
$matched->length > 0 not defined $show_legend $show_legend
Truth table0%0/4
A && not(B) or C
A= $matched->length > 0B= not defined $show_legendC= $show_legend
ABCresult
0XX0
1000
11X1
1011
63 and ( not defined $show_legend or $show_legend ) )
64 }
65 @$layers
66 )
67 {
68 0 next;
69 }
70  
71 0 ▶ if (defined $guide) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $guide) 0 0 0
72 0 push @gdefs, $guide;
73 }
74 }
75 }
76 0 return \@gdefs;
77 2 }
78  
79 0 ▶method set($key, $guide) { $self->_guides->{$key} = $guide; }
Subroutine set: not called CC=3 SCAR=22.8
Pod undocumented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 3 and Function::Parameters::_croak('Too few arguments for method set (expected 3, got ' . @_ . ')') 0 0 0
@_ > 3 and Function::Parameters::_croak('Too many arguments for method set (expected 3, got ' . @_ . ')') 0 0 0
80 0 ▶method get_guide($key) { $self->_guides->{$key}; }
Subroutine get_guide: not called CC=3 SCAR=22.8
Pod undocumented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 2 and Function::Parameters::_croak('Too few arguments for method get_guide (expected 2, got ' . @_ . ')') 0 0 0
@_ > 2 and Function::Parameters::_croak('Too many arguments for method get_guide (expected 2, got ' . @_ . ')') 0 0 0
81  
82 0 ▶method guides() {
Subroutine guides: not called CC=3 SCAR=24.8
Pod undocumented
Branch: 2 branches
BranchTrueFalseTotal
@_ < 1 and Function::Parameters::_croak('Too few arguments for method guides (expected 1, got ' . @_ . ')') 0 0 0
@_ > 1 and Function::Parameters::_croak('Too many arguments for method guides (expected 1, got ' . @_ . ')') 0 0 0
83 0 my $guides = $self->_guides;
84 0 return [ map { $guides->{$_} } sort keys %$guides ];
85 2 }
86  
87 0 ▶classmethod _validate_guide ($guide) {
Subroutine _validate_guide: not called CC=4 SCAR=30.0
Branch: 2 branches
BranchTrueFalseTotal
@_ < 2 and Function::Parameters::_croak('Too few arguments for classmethod _validate_guide (expected 2, got ' . @_ . ')') 0 0 0
@_ > 2 and Function::Parameters::_croak('Too many arguments for classmethod _validate_guide (expected 2, got ' . @_ . ')') 0 0 0
88 0 ▶ if ($guide->$_DOES('Chart::GGPlot::Guide')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($guide->$Chart::GGPlot::Guides::_DOES('Chart::GGPlot::Guide')) { } 0 0 0
89 0 return $guide;
90 } else {
91 0 my $class_guide = 'Chart::GGPlot::Guide::' . ucfirst($guide);
92 0 load $class_guide;
93 0 return $class_guide->new;
94 }
95 2 }
96  
97 0 ▶classmethod _matched_aes ($layer, $guide, $defaults) {
Subroutine _matched_aes: not called CC=4 SCAR=30.0
Branch: 2 branches
BranchTrueFalseTotal
@_ < 4 and Function::Parameters::_croak('Too few arguments for classmethod _matched_aes (expected 4, got ' . @_ . ')') 0 0 0
@_ > 4 and Function::Parameters::_croak('Too many arguments for classmethod _matched_aes (expected 4, got ' . @_ . ')') 0 0 0
98 my $all = [
99 uniq(
100 0 @{ $layer->mapping->names },
101 @{
102 0 ▶ ( $layer->inherit_aes ? $defaults : $layer->stat->default_aes )
Branch: 1 branch
BranchTrueFalseTotal
$layer->inherit_aes ? : 0 0 0
103 ->names
104 }
105 )
106 ];
107 0 my $geom_aes = [ @{ $layer->geom->required_aes },
108 0 @{ $layer->geom->default_aes->names } ];
109 0 my $matched = $all->intersect($geom_aes)->intersect( $guide->key->names );
110 return $matched->setdiff(
111 0 [ @{ $layer->geom_params->names }, @{ $layer->aes_params->names } ] );
112 2 }
113  
114 2 1;
115  
116 __END__
« Chart/GGPlot/Util/Stats.pm ↑ Summary Chart/GGPlot/Stat/Smooth.pm »