ColorThemeBase/Constructor.pm

filter: Statementstmt 92.0% 23 / 25 Branchbran 83.3% 10 / 12 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 4 / 4 Subroutinesub 100% 2 / 2 Podpod 0.0% 0 / 1 totaltotal 90.0% 45 / 50 CC 11 SCAR 23.4
CC
11
Cov
91%
new
11.2
BEGIN
1.0
CRAP 10.3
« ColorThemeBase/Static/FromObjectColors.pm ↑ Summary ColorTheme/Test/Dynamic.pm »
1 package ColorThemeBase::Constructor;
2  
3 8 ▶use strict 'subs', 'vars';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 #use warnings;
5  
6 8 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
7 8 our $DATE = '2024-07-17'; # DATE
8 8 our $DIST = 'ColorThemeBase-Static'; # DIST
9 8 our $VERSION = '0.009'; # VERSION
10  
11 7 ▶sub new {
Subroutine new: called CC=11 SCAR=24.1
Pod undocumented
12 7 my $class = shift;
13  
14 # check that %THEME exists
15 7 my $theme_hash = \%{"$class\::THEME"};
16 7 ▶ unless (defined $theme_hash->{v}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $theme_hash->{"v"}) 0 7 7
17 0 die "Class $class does not define \%THEME with 'v' key";
18 }
19 7 ▶ unless ($theme_hash->{v} == 2) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($theme_hash->{"v"} == 2) 0 7 7
20 0 die "\%$class\::THEME's v is $theme_hash->{v}, I only support v=2";
21 }
22  
23 # check for known and required arguments
24 7 my %args = @_;
25 {
26 7 my $args_spec = $theme_hash->{args};
27 7 ▶ last unless $args_spec;
Branch: 1 branch
BranchTrueFalseTotal
unless $args_spec 4 3 7
28 3 for my $arg_name (keys %args) {
29 3 ▶ die "Unknown argument '$arg_name'" unless $args_spec->{$arg_name};
Branch: 1 branch
BranchTrueFalseTotal
unless $args_spec->{$arg_name} 1 2 3
30 }
31 2 for my $arg_name (keys %$args_spec) {
32 die "Missing required argument '$arg_name'"
33 4 ▶ if $args_spec->{$arg_name}{req} && !exists($args{$arg_name});
Branch: 1 branch
BranchTrueFalseTotal
if $args_spec->{$arg_name}{"req"} and not exists $args{$arg_name} 1 3 4
Condition100%3/3
$args_spec->{$arg_name}{"req"} and not exists $args{$arg_name}
!ll&&!rl&&r
211
MC/DC100%2/2
$args_spec->{$arg_name}{"req"} and not exists $args{$arg_name}
$args_spec->{$arg_name}{"req"} not exists $args{$arg_name}
Truth table100%3/3
A and not(B)
A= $args_spec->{$arg_name}{"req"}B= not exists $args{$arg_name}
ABresult
0X0
100
111
34 # apply default
35 $args{$arg_name} = $args_spec->{$arg_name}{default}
36 if !defined($args{$arg_name}) &&
37 3 ▶ exists $args_spec->{$arg_name}{default};
Branch: 1 branch
BranchTrueFalseTotal
if not defined $args{$arg_name} and exists $args_spec->{$arg_name}{"default"} 1 2 3
Condition100%3/3
not defined $args{$arg_name} and exists $args_spec->{$arg_name}{"default"}
!ll&&!rl&&r
111
MC/DC100%2/2
not defined $args{$arg_name} and exists $args_spec->{$arg_name}{"default"}
not defined $args{$arg_name} exists $args_spec->{$arg_name}{"default"}
Truth table100%3/3
not(A) and B
A= not defined $args{$arg_name}B= exists $args_spec->{$arg_name}{"default"}
ABresult
0X0
100
111
38 }
39 }
40  
41 bless {
42 5 args => \%args,
43  
44 # we store this because applying roles to object will rebless the object
45 # into some other package.
46 orig_class => $class,
47 }, $class;
48 }
49  
50 8 1;
51 # ABSTRACT: Provide new()
52  
53 __END__
« ColorThemeBase/Static/FromObjectColors.pm ↑ Summary ColorTheme/Test/Dynamic.pm »