| 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
| |||||||||||||||||||||||||||||
| 17 | 0 | die "Class $class does not define \%THEME with 'v' key"; | |||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||
| 19 | 7 | ▶ | unless ($theme_hash->{v} == 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 28 | 3 | for my $arg_name (keys %args) { | |||||||||||||||||||||||||||
| 29 | 3 | ▶ | die "Unknown argument '$arg_name'" unless $args_spec->{$arg_name}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
$args_spec->{$arg_name}{"req"} and not exists $args{$arg_name}
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}
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
not defined $args{$arg_name} and exists $args_spec->{$arg_name}{"default"}
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"}
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||