| 1 | package Math::Geometry::Construction::Role::AlternativeSources; | ||||||||||||||
| 2 | 16 | ▶ | use Moose::Role; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 3 | |||||||||||||||
| 4 | 16 | ▶ | use 5.008008; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | |||||||||||||||
| 6 | 16 | ▶ | use Carp; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | |||||||||||||||
| 8 | =head1 NAME | ||||||||||||||
| 9 | |||||||||||||||
| 10 | C<Math::Geometry::Construction::Role::AlternativeSources> - one out of some | ||||||||||||||
| 11 | |||||||||||||||
| 12 | =head1 VERSION | ||||||||||||||
| 13 | |||||||||||||||
| 14 | Version 0.024 | ||||||||||||||
| 15 | |||||||||||||||
| 16 | =cut | ||||||||||||||
| 17 | |||||||||||||||
| 18 | 6 | our $VERSION = '0.024'; | |||||||||||||
| 19 | |||||||||||||||
| 20 | 22 | ▶ | sub alternatives { | ||||||||||||
|
Subroutine
alternatives: called CC=8 SCAR=20.8
Pod
undocumented
| |||||||||||||||
| 21 | 22 | my ($class, %args) = @_; | |||||||||||||
| 22 | 22 | my $meta = Class::MOP::Class->initialize($class); | |||||||||||||
| 23 | |||||||||||||||
| 24 | # complete spec (except triggers) | ||||||||||||||
| 25 | 22 | ▶ | while(my ($alt_name, $alt_spec) = each %{$args{alternatives}}) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 26 | $alt_spec->{is} = 'rw' | ||||||||||||||
| 27 | 70 | ▶ | unless(exists($alt_spec->{is})); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 28 | $alt_spec->{reader} = '_'.$alt_name | ||||||||||||||
| 29 | 70 | ▶ | unless(exists($alt_spec->{reader})); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 30 | $alt_spec->{predicate} = '_has_'.$alt_name | ||||||||||||||
| 31 | 70 | ▶ | unless(exists($alt_spec->{predicate})); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 32 | $alt_spec->{clearer} = '_clear_'.$alt_name | ||||||||||||||
| 33 | 70 | ▶ | unless(exists($alt_spec->{clearer})); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 34 | } | ||||||||||||||
| 35 | |||||||||||||||
| 36 | # create attributes with triggers | ||||||||||||||
| 37 | 22 | ▶ | while(my ($alt_name, $alt_spec) = each %{$args{alternatives}}) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 38 | 352 | ▶ | my $_rules = sub { | ||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||
| 39 | 352 | my ($self) = @_; | |||||||||||||
| 40 | |||||||||||||||
| 41 | 352 | foreach(keys %{$args{alternatives}}) { | |||||||||||||
| 42 | 1076 | ▶ | unless($_ eq $alt_name) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 43 | 724 | my $clearer = $args{alternatives}->{$_}->{clearer}; | |||||||||||||
| 44 | 724 | $self->$clearer; | |||||||||||||
| 45 | } | ||||||||||||||
| 46 | } | ||||||||||||||
| 47 | |||||||||||||||
| 48 | 352 | ▶ | $self->clear_global_buffer if($args{clear_buffer}); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 49 | 70 | }; | |||||||||||||
| 50 | $alt_spec->{trigger} = $_rules | ||||||||||||||
| 51 | 70 | ▶ | unless(exists($alt_spec->{trigger})); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 52 | |||||||||||||||
| 53 | 70 | $meta->add_attribute($alt_name, %$alt_spec); | |||||||||||||
| 54 | } | ||||||||||||||
| 55 | |||||||||||||||
| 56 | 79 | ▶ | my $_check = sub { | ||||||||||||
|
Subroutine
_check_value_sources: called CC=3 SCAR=11.0
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||
| 57 | 79 | my ($self) = @_; | |||||||||||||
| 58 | 79 | foreach(keys %{$args{alternatives}}) { | |||||||||||||
| 59 | 142 | my $predicate = $args{alternatives}->{$_}->{predicate}; | |||||||||||||
| 60 | 142 | ▶ | return if($self->$predicate); | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 61 | } | ||||||||||||||
| 62 | croak('At least one of the attributes '. | ||||||||||||||
| 63 | 2 | join(', ', keys %{$args{alternatives}}). | |||||||||||||
| 64 | ' has to be specified when construction a '. | ||||||||||||||
| 65 | $class.' object'); | ||||||||||||||
| 66 | 22 | }; | |||||||||||||
| 67 | |||||||||||||||
| 68 | 22 | $meta->add_method('_check_'.$args{name} => $_check); | |||||||||||||
| 69 | } | ||||||||||||||
| 70 | |||||||||||||||
| 71 | 6 | 1; | |||||||||||||
| 72 | |||||||||||||||
| 73 | |||||||||||||||
| 74 | __END__ | ||||||||||||||