| 1 | package BorderStyleRole::Spec::Basic; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 5 | ▶ | use Role::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | #use Role::Tiny::With; | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 5 | our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY | |||||||||||||||||||||||||||
| 10 | 5 | our $DATE = '2023-07-14'; # DATE | |||||||||||||||||||||||||||
| 11 | 5 | our $DIST = 'BorderStyle'; # DIST | |||||||||||||||||||||||||||
| 12 | 5 | our $VERSION = '3.0.3'; # VERSION | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | ### requires | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 5 | requires 'get_border_char'; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | ### provides | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=11 SCAR=46.6
Pod
documented
| |||||||||||||||||||||||||||||
| 21 | 5 | ▶ | no strict 'refs'; ## no critic: TestingAndDebugging::ProhibitNoStrict | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 0 | my $class = shift; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | # check that %BORDER exists | ||||||||||||||||||||||||||||
| 25 | 0 | my $bs_hash = \%{"$class\::BORDER"}; | |||||||||||||||||||||||||||
| 26 | 0 | ▶ | unless (defined $bs_hash->{v}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 0 | die "Class $class does not define \%BORDER with 'v' key"; | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | 0 | ▶ | unless ($bs_hash->{v} == 3) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | 0 | die "\%$class\::BORDER's v is $bs_hash->{v}, I only support v=2"; | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | # check for known and required arguments | ||||||||||||||||||||||||||||
| 34 | 0 | my %args = @_; | |||||||||||||||||||||||||||
| 35 | { | ||||||||||||||||||||||||||||
| 36 | 0 | my $args_spec = $bs_hash->{args}; | |||||||||||||||||||||||||||
| 37 | 0 | ▶ | last unless $args_spec; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 0 | for my $arg_name (keys %args) { | |||||||||||||||||||||||||||
| 39 | 0 | ▶ | die "Unknown argument '$arg_name'" unless $args_spec->{$arg_name}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | 0 | for my $arg_name (keys %$args_spec) { | |||||||||||||||||||||||||||
| 42 | die "Missing required argument '$arg_name'" | ||||||||||||||||||||||||||||
| 43 | 0 | ▶ | if $args_spec->{$arg_name}{req} && !exists($args{$arg_name}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$args_spec->{$arg_name}{"req"} and not exists $args{$arg_name}
MC/DC0%0/2
$args_spec->{$arg_name}{"req"} and not exists $args{$arg_name}
$args_spec->{$arg_name}{"req"}
not exists $args{$arg_name}
Truth table0%0/3
A and not(B)
A= $args_spec->{$arg_name}{"req"}B= not exists $args{$arg_name}
| |||||||||||||||||||||||||||||
| 44 | # apply default | ||||||||||||||||||||||||||||
| 45 | $args{$arg_name} = $args_spec->{$arg_name}{default} | ||||||||||||||||||||||||||||
| 46 | if !defined($args{$arg_name}) && | ||||||||||||||||||||||||||||
| 47 | 0 | ▶ | exists $args_spec->{$arg_name}{default}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $args{$arg_name} and exists $args_spec->{$arg_name}{"default"}
MC/DC0%0/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 table0%0/3
not(A) and B
A= not defined $args{$arg_name}B= exists $args_spec->{$arg_name}{"default"}
| |||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | bless { | ||||||||||||||||||||||||||||
| 52 | 0 | args => \%args, | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | # we store this because applying roles to object will rebless the object | ||||||||||||||||||||||||||||
| 55 | # into some other package. | ||||||||||||||||||||||||||||
| 56 | orig_class => $class, | ||||||||||||||||||||||||||||
| 57 | }, $class; | ||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | sub get_struct { | ||||||||||||||||||||||||||
|
Subroutine
get_struct: not called CC=2 SCAR=12.6
Pod
documented
| |||||||||||||||||||||||||||||
| 61 | 5 | ▶ | no strict 'refs'; ## no critic: TestingAndDebugging::ProhibitNoStrict | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 62 | 0 | my $self_or_class = shift; | |||||||||||||||||||||||||||
| 63 | 0 | ▶ | if (ref $self_or_class) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | 0 | \%{"$self_or_class->{orig_class}::BORDER"}; | |||||||||||||||||||||||||||
| 65 | } else { | ||||||||||||||||||||||||||||
| 66 | 0 | \%{"$self_or_class\::BORDER"}; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 0 | ▶ | sub get_args { | ||||||||||||||||||||||||||
|
Subroutine
get_args: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 71 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 72 | 0 | $self->{args}; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 5 | my @role_prefixes = qw(BorderStyleRole); | |||||||||||||||||||||||||||
| 76 | 0 | ▶ | sub apply_roles { | ||||||||||||||||||||||||||
|
Subroutine
apply_roles: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 77 | 0 | my ($obj, @unqualified_roles) = @_; | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | my @roles_to_apply; | |||||||||||||||||||||||||||
| 80 | ROLE: | ||||||||||||||||||||||||||||
| 81 | 0 | for my $ur (@unqualified_roles) { | |||||||||||||||||||||||||||
| 82 | PREFIX: | ||||||||||||||||||||||||||||
| 83 | 0 | for my $prefix (@role_prefixes) { | |||||||||||||||||||||||||||
| 84 | 0 | my ($mod, $modpm); | |||||||||||||||||||||||||||
| 85 | 0 | $mod = "$prefix\::$ur"; | |||||||||||||||||||||||||||
| 86 | 0 | ($modpm = "$mod.pm") =~ s!::!/!g; | |||||||||||||||||||||||||||
| 87 | 0 | eval { require $modpm; 1 }; | |||||||||||||||||||||||||||
| 88 | 0 | ▶ | unless ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | #print "D:$mod\n"; | ||||||||||||||||||||||||||||
| 90 | 0 | push @roles_to_apply, $mod; | |||||||||||||||||||||||||||
| 91 | 0 | next ROLE; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | 0 | die "Can't find role '$ur' to apply (searched these prefixes: ". | |||||||||||||||||||||||||||
| 95 | join(", ", @role_prefixes); | ||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 0 | Role::Tiny->apply_roles_to_object($obj, @roles_to_apply); | |||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | # return something useful | ||||||||||||||||||||||||||||
| 101 | 0 | $obj; | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 5 | 1; | |||||||||||||||||||||||||||
| 105 | # ABSTRACT: Required methods for all BorderStyle::* modules | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | __END__ | ||||||||||||||||||||||||||||