| 1 | package Class::Accessor::Validated; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Class::Accessor::Fast; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Class::Accessor; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Exporter qw(import); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 1 | our @EXPORT_OK = qw(setup_accessors); | |||||||||||||||||||||||||||
| 12 | 1 | our $VERSION = '0.04'; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 1 | our $FOLLOW_BAD_PRACTICE = 0; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use parent qw(Exporter Class::Accessor::Fast); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | ######################################################################## | ||||||||||||||||||||||||||||
| 19 | 6 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=15 SCAR=27.2
Pod
documented
| |||||||||||||||||||||||||||||
| 20 | ######################################################################## | ||||||||||||||||||||||||||||
| 21 | 6 | my ( $class, @args ) = @_; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 6 | ▶ | my $arg_ref = ref $args[0] ? $args[0] : {@args}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 6 | my @bad_keys; | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 6 | for my $maybe_valid_key ( keys %{$arg_ref} ) { | |||||||||||||||||||||||||||
| 28 | 10 | ▶ | my $follows_best_practice = $class->can("set_$maybe_valid_key") && $class->can("get_$maybe_valid_key"); | ||||||||||||||||||||||||||
|
Condition66%2/3
$class->can("set_$maybe_valid_key") && $class->can("get_$maybe_valid_key")
MC/DC50%1/2
$class->can("set_$maybe_valid_key") && $class->can("get_$maybe_valid_key")
$class->can("set_$maybe_valid_key")
$class->can("get_$maybe_valid_key")
Truth table66%2/3
A && B
A= $class->can("set_$maybe_valid_key")B= $class->can("get_$maybe_valid_key")
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 10 | ▶ | my $follows_bad_practice = $FOLLOW_BAD_PRACTICE && $class->can($maybe_valid_key); | ||||||||||||||||||||||||||
|
Condition33%1/3
$Class::Accessor::Validated::FOLLOW_BAD_PRACTICE && $class->can($maybe_valid_key)
MC/DC0%0/2
$Class::Accessor::Validated::FOLLOW_BAD_PRACTICE && $class->can($maybe_valid_key)
$Class::Accessor::Validated::FOLLOW_BAD_PRACTICE
$class->can($maybe_valid_key)
Truth table33%1/3
A && B
A= $Class::Accessor::Validated::FOLLOW_BAD_PRACTICEB= $class->can($maybe_valid_key)
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 10 | ▶ | next if $follows_best_practice || $follows_bad_practice; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$follows_best_practice or $follows_bad_practice
MC/DC50%1/2
$follows_best_practice or $follows_bad_practice
$follows_best_practice
$follows_bad_practice
Truth table66%2/3
A or B
A= $follows_best_practiceB= $follows_bad_practice
| |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 1 | push @bad_keys, $maybe_valid_key; | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 1 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 6 | my %required_keys; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 6 | for my $ancestor_class ( reverse _linear_isa($class) ) { | |||||||||||||||||||||||||||
| 42 | 32 | my $symbol = $ancestor_class . '::ATTRIBUTES'; | |||||||||||||||||||||||||||
| 43 | 32 | my $attr_ref = *{$symbol}{HASH}; | |||||||||||||||||||||||||||
| 44 | 32 | ▶ | next if !$attr_ref; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 8 | %required_keys = ( %required_keys, %{$attr_ref} ); | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 6 | my @missing_required_keys; | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 6 | for my $maybe_required_key ( keys %required_keys ) { | |||||||||||||||||||||||||||
| 52 | 14 | ▶ | next if !$required_keys{$maybe_required_key}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 8 | ▶ | next if exists $arg_ref->{$maybe_required_key}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 2 | push @missing_required_keys, $maybe_required_key; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 6 | my @errors; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 6 | ▶ | if (@bad_keys) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 1 | push @errors, 'invalid argument(s): ' . join ', ', @bad_keys; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 6 | ▶ | if (@missing_required_keys) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | 2 | push @errors, 'required argument(s): ' . join ', ', @missing_required_keys; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 6 | ▶ | if (@errors) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | 3 | die join '; ', @errors; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 3 | return $class->SUPER::new($arg_ref); | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | ######################################################################## | ||||||||||||||||||||||||||||
| 75 | 0 | ▶ | sub setup_accessors { | ||||||||||||||||||||||||||
|
Subroutine
setup_accessors: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 76 | ######################################################################## | ||||||||||||||||||||||||||||
| 77 | 0 | my ( $class, @keys ) = @_; | |||||||||||||||||||||||||||
| 78 | 0 | Class::Accessor->follow_best_practice($class); | |||||||||||||||||||||||||||
| 79 | 0 | Class::Accessor::Fast->mk_accessors( $class, @keys ); | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 0 | return 1; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | ######################################################################## | ||||||||||||||||||||||||||||
| 85 | 6 | ▶ | sub _linear_isa { | ||||||||||||||||||||||||||
|
Subroutine
_linear_isa: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 86 | ######################################################################## | ||||||||||||||||||||||||||||
| 87 | 6 | my ($start_class) = @_; | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 1 | ▶ | no strict 'refs'; ## no critic | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 6 | my @isa_list; | |||||||||||||||||||||||||||
| 92 | my %seen; | ||||||||||||||||||||||||||||
| 93 | 6 | my @queue = ($start_class); | |||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 6 | ▶ | while ( my $current = shift @queue ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | 40 | ▶ | next if $seen{$current}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | 32 | $seen{$current} = 1; | |||||||||||||||||||||||||||
| 98 | 32 | push @isa_list, $current; | |||||||||||||||||||||||||||
| 99 | 32 | unshift @queue, @{ $current . '::ISA' }; | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 6 | return @isa_list; | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 1 | 1; | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | __END__ | ||||||||||||||||||||||||||||