| 1 | package Context::Set; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 6 | our $VERSION = '0.02'; | |||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 6 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 6 | has 'name' => ( is => 'ro', isa => 'Str', default => 'UNIVERSE' ); | |||||||||||||||||||||||||||
| 9 | 65 | ▶ | has 'properties' => ( is => 'rw' , isa => 'HashRef' , required => 1 , default => sub{ {}; } ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 273 | ▶ | sub fullname{ | ||||||||||||||||||||||||||
|
Subroutine
fullname: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 13 | 273 | my ($self) = @_; | |||||||||||||||||||||||||||
| 14 | 273 | return $self->name(); | |||||||||||||||||||||||||||
| 15 | } | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 31 | ▶ | sub is_inside{ | ||||||||||||||||||||||||||
|
Subroutine
is_inside: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 18 | 31 | my ($self , $name) = @_; | |||||||||||||||||||||||||||
| 19 | 31 | return $self->name() eq $name; | |||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 8 | ▶ | sub restrict{ | ||||||||||||||||||||||||||
|
Subroutine
restrict: called CC=2 SCAR=7.4
Pod
documented
| |||||||||||||||||||||||||||||
| 23 | 8 | my ($self, $restriction_name) = @_; | |||||||||||||||||||||||||||
| 24 | 8 | ▶ | unless( $restriction_name ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | 0 | confess("Missing restriction_name"); | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | ## Avoid circular dependencies. | ||||||||||||||||||||||||||||
| 28 | 8 | require Context::Set::Restriction; | |||||||||||||||||||||||||||
| 29 | 8 | return Context::Set::Restriction->new({ name => $restriction_name, | |||||||||||||||||||||||||||
| 30 | restricted => $self }); | ||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 6 | ▶ | sub unite{ | ||||||||||||||||||||||||||
|
Subroutine
unite: called CC=3 SCAR=12.7
Pod
documented
| |||||||||||||||||||||||||||||
| 35 | 6 | my ($self, $other) = @_; | |||||||||||||||||||||||||||
| 36 | 6 | ▶ | unless( $other && $other->isa('Context::Set') ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$other and $other->isa("Context::Set")
MC/DC0%0/2
$other and $other->isa("Context::Set")
$other
$other->isa("Context::Set")
Truth table33%1/3
A and B
A= $otherB= $other->isa("Context::Set")
| |||||||||||||||||||||||||||||
| 37 | 0 | confess("Missing other Context in unite"); | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | 6 | require Context::Set::Union; | |||||||||||||||||||||||||||
| 40 | 6 | return Context::Set::Union->new({ contexts => [ $self, $other ] }); | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 38 | ▶ | sub set_property{ | ||||||||||||||||||||||||||
|
Subroutine
set_property: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||
| 45 | 38 | my ($self, $prop_name, $value) = @_; | |||||||||||||||||||||||||||
| 46 | 38 | ▶ | unless( defined $prop_name ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 0 | confess("prop_name has to be a defined value"); | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | 38 | $self->properties()->{$prop_name} = $value; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 28 | ▶ | sub get_property{ | ||||||||||||||||||||||||||
|
Subroutine
get_property: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 54 | 28 | my ($self, $prop_name) = @_; | |||||||||||||||||||||||||||
| 55 | 28 | ▶ | unless( $self->has_property($prop_name) ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 4 | confess("No property named $prop_name in ".$self->name()); | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | 24 | return $self->properties()->{$prop_name}; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 54 | ▶ | sub has_property{ | ||||||||||||||||||||||||||
|
Subroutine
has_property: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 63 | 54 | my ($self, $prop_name) = @_; | |||||||||||||||||||||||||||
| 64 | 54 | return exists $self->properties()->{$prop_name}; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 4 | ▶ | sub delete_property{ | ||||||||||||||||||||||||||
|
Subroutine
delete_property: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||
| 68 | 4 | my ($self, $prop_name) = @_; | |||||||||||||||||||||||||||
| 69 | 4 | ▶ | unless( $self->has_property($prop_name) ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 0 | confess("No property named $prop_name in ".$self->name()." cannot delete it"); | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | 4 | return delete $self->properties()->{$prop_name}; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 6 | ▶ | sub lookup{ | ||||||||||||||||||||||||||
|
Subroutine
lookup: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||||||||||||||||||||
| 76 | 6 | my ($self, $prop_name) = @_; | |||||||||||||||||||||||||||
| 77 | 0 | ▶ | unless( $prop_name ){ confess("Missing prop_name"); } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | 6 | ▶ | return $self if $self->properties()->{$prop_name}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | 3 | return $self->_lookup_parents($prop_name); | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | ▶ | sub _lookup_parents{ | ||||||||||||||||||||||||||
|
Subroutine
_lookup_parents: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 83 | 0 | my ($self, $pname) = @_; | |||||||||||||||||||||||||||
| 84 | 0 | return undef; | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 6 | __PACKAGE__->meta->make_immutable(); | |||||||||||||||||||||||||||
| 88 | 6 | 1; | |||||||||||||||||||||||||||
| 89 | __END__ | ||||||||||||||||||||||||||||