| 1 | package EntityModel::Class::Accessor::Array; | ||||||||||||
| 2 | 3 | $EntityModel::Class::Accessor::Array::VERSION = '0.016'; | |||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | |||||||||||||
| 6 | 3 | ▶ | use parent qw{EntityModel::Class::Accessor}; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | |||||||||||||
| 8 | 3 | ▶ | use EntityModel::Array; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 3 | ▶ | use EntityModel::Log ':all'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | 3 | ▶ | use Class::ISA; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | |||||||||||||
| 12 | 3 | my %watcher; | |||||||||||
| 13 | |||||||||||||
| 14 | =head1 NAME | ||||||||||||
| 15 | |||||||||||||
| 16 | EntityModel::Class::Accessor::Array - generic class accessor for arrays | ||||||||||||
| 17 | |||||||||||||
| 18 | =head1 VERSION | ||||||||||||
| 19 | |||||||||||||
| 20 | Version 0.016 | ||||||||||||
| 21 | |||||||||||||
| 22 | =head1 DESCRIPTION | ||||||||||||
| 23 | |||||||||||||
| 24 | See L<EntityModel::Class>. | ||||||||||||
| 25 | |||||||||||||
| 26 | =head1 METHODS | ||||||||||||
| 27 | |||||||||||||
| 28 | =cut | ||||||||||||
| 29 | |||||||||||||
| 30 | =head2 method_list | ||||||||||||
| 31 | |||||||||||||
| 32 | Returns the method definition to add to the class. | ||||||||||||
| 33 | |||||||||||||
| 34 | =cut | ||||||||||||
| 35 | |||||||||||||
| 36 | 1 | ▶ | sub method_list { | ||||||||||
|
Subroutine
method_list: called CC=2 SCAR=9.5
Pod
documented
| |||||||||||||
| 37 | 1 | my ($class, %opt) = @_; | |||||||||||
| 38 | 1 | my $k = $opt{k}; | |||||||||||
| 39 | 1 | ▶ | if(my $pre = $opt{pre}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 40 | 0 | ▶ | return sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=6 SCAR=37.4
| |||||||||||||
| 41 | 0 | my $self = shift; | |||||||||||
| 42 | 0 | ▶ | die "Options not supported for Array" if @_; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 43 | 0 | ▶ | $opt{pre}->($self, @_) or return; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 44 | 0 | ▶ | unless($self->{$k}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 45 | 0 | ▶ | my @watchers = map { @{ $watcher{$_}->{$k} // [] } } Class::ISA::self_and_super_path(ref $self); | ||||||||||
|
Condition0%0/2
$watcher{$_}{$k} // []
MC/DC0%0/1
$watcher{$_}{$k} // []
$watcher{$_}{$k}
Truth table0%0/2
A
A= $watcher{$_}{$k}
| |||||||||||||
| 46 | 0 | logDebug("Watcher for [%s] method [%s] has %d entries", ref $self, $k, scalar @watchers); | |||||||||||
| 47 | $self->{$k} = EntityModel::Array->new($self->{$k}, | ||||||||||||
| 48 | (@watchers) | ||||||||||||
| 49 | 0 | ▶ | ? (onchange => [ sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||
| 50 | 0 | logDebug("Check [%s] for [%s]", ref $self, $k); | |||||||||||
| 51 | # Pass value only | ||||||||||||
| 52 | 0 | $_->($self, @_) foreach @watchers; | |||||||||||
| 53 | 0 | ▶ | } ]) : () | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 54 | ); | ||||||||||||
| 55 | } | ||||||||||||
| 56 | 0 | return $self->{$k}; | |||||||||||
| 57 | 0 | }; | |||||||||||
| 58 | } else { | ||||||||||||
| 59 | 7 | ▶ | return sub { | ||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||
| 60 | 7 | my $self = shift; | |||||||||||
| 61 | 7 | ▶ | die "Options not supported for Array" if @_; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 62 | 7 | ▶ | unless($self->{$k}) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 63 | my @watchers = map { | ||||||||||||
| 64 | 1 | ▶ | @{ $watcher{$_}->{$k} // [] } | ||||||||||
|
Condition100%2/2
$watcher{$_}{$k} // []
MC/DC100%1/1
$watcher{$_}{$k} // []
$watcher{$_}{$k}
Truth table100%2/2
A
A= $watcher{$_}{$k}
| |||||||||||||
| 65 | } Class::ISA::self_and_super_path(ref $self); | ||||||||||||
| 66 | |||||||||||||
| 67 | 1 | logDebug("Watcher for [%s] method [%s] has %d entries", ref $self, $k, scalar @watchers); | |||||||||||
| 68 | $self->{$k} = EntityModel::Array->new($self->{$k}, | ||||||||||||
| 69 | (@watchers) | ||||||||||||
| 70 | 4 | ▶ | ? (onchange => [ $self->sap(sub { | ||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||
| 71 | 4 | my $self = shift; | |||||||||||
| 72 | 4 | logDebug("Check [%s] for [%s]", ref $self, $k); | |||||||||||
| 73 | # Pass value only | ||||||||||||
| 74 | 4 | $_->($self, @_) foreach @watchers; | |||||||||||
| 75 | 1 | ▶ | }) ]) : () | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 76 | ); | ||||||||||||
| 77 | } | ||||||||||||
| 78 | 7 | return $self->{$k}; | |||||||||||
| 79 | 1 | }; | |||||||||||
| 80 | } | ||||||||||||
| 81 | } | ||||||||||||
| 82 | |||||||||||||
| 83 | =head2 add_watcher | ||||||||||||
| 84 | |||||||||||||
| 85 | Add this to the list of watchers for the class. | ||||||||||||
| 86 | |||||||||||||
| 87 | =cut | ||||||||||||
| 88 | |||||||||||||
| 89 | 1 | ▶ | sub add_watcher { | ||||||||||
|
Subroutine
add_watcher: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 90 | 1 | my ($class, $pkg, $meth, @sub) = @_; | |||||||||||
| 91 | 1 | logDebug("Watching [%s] for [%s]", $meth, $pkg); | |||||||||||
| 92 | 1 | push @{$watcher{$pkg}->{$meth}}, @sub; | |||||||||||
| 93 | 1 | return 1; | |||||||||||
| 94 | } | ||||||||||||
| 95 | |||||||||||||
| 96 | 3 | 1; | |||||||||||
| 97 | |||||||||||||
| 98 | __END__ | ||||||||||||