| 1 | package WWW::Google::Contacts::Roles::HasTypeAndLabel; | ||||||||||||||||||||||||||||
| 2 | { | ||||||||||||||||||||||||||||
| 3 | 20 | $WWW::Google::Contacts::Roles::HasTypeAndLabel::VERSION = '0.39'; | |||||||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 20 | ▶ | use MooseX::Role::Parameterized; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 20 | ▶ | use MooseX::Types::Moose qw( ArrayRef Str ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 20 | ▶ | use WWW::Google::Contacts::InternalTypes qw( Rel ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 20 | ▶ | use Perl6::Junction qw( any ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 20 | parameter valid_types => ( | |||||||||||||||||||||||||||
| 12 | isa => ArrayRef, | ||||||||||||||||||||||||||||
| 13 | required => 1, | ||||||||||||||||||||||||||||
| 14 | ); | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 20 | parameter default_type => ( | |||||||||||||||||||||||||||
| 17 | isa => Str, | ||||||||||||||||||||||||||||
| 18 | required => 1, | ||||||||||||||||||||||||||||
| 19 | ); | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 115 | ▶ | role { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.2
| |||||||||||||||||||||||||||||
| 22 | 115 | my $param = shift; | |||||||||||||||||||||||||||
| 23 | 115 | my $valid_types = $param->valid_types; | |||||||||||||||||||||||||||
| 24 | 115 | my $default_type = $param->default_type; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | has type => ( | ||||||||||||||||||||||||||||
| 27 | isa => Rel, | ||||||||||||||||||||||||||||
| 28 | is => 'rw', | ||||||||||||||||||||||||||||
| 29 | traits => ['XmlField'], | ||||||||||||||||||||||||||||
| 30 | xml_key => 'rel', | ||||||||||||||||||||||||||||
| 31 | predicate => 'has_type', | ||||||||||||||||||||||||||||
| 32 | trigger => \&_type_set, | ||||||||||||||||||||||||||||
| 33 | 3 | ▶ | include_in_xml => sub { return $_[0]->has_valid_type }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 34 | 10 | ▶ | default => sub { to_Rel($default_type) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 35 | 115 | coerce => 1, | |||||||||||||||||||||||||||
| 36 | ); | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | has label => ( | ||||||||||||||||||||||||||||
| 39 | isa => Str, | ||||||||||||||||||||||||||||
| 40 | is => 'rw', | ||||||||||||||||||||||||||||
| 41 | traits => ['XmlField'], | ||||||||||||||||||||||||||||
| 42 | xml_key => 'label', | ||||||||||||||||||||||||||||
| 43 | trigger => \&_label_set, | ||||||||||||||||||||||||||||
| 44 | predicate => 'has_label', | ||||||||||||||||||||||||||||
| 45 | 3 | ▶ | include_in_xml => sub { return !$_[0]->has_valid_type }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 46 | 10 | ▶ | default => sub { $default_type }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 47 | 115 | ); | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 6 | ▶ | method has_valid_type => sub { | ||||||||||||||||||||||||||
|
Subroutine
has_valid_type: called CC=2 SCAR=9.2
Subroutine
__ANON__: not called CC=2 SCAR=9.2
| |||||||||||||||||||||||||||||
| 50 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 51 | 0 | ▶ | return any( @{$valid_types} ) eq $self->type->name ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 52 | 115 | }; | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 0 | ▶ | method default_type => sub { | ||||||||||||||||||||||||||
|
Subroutine
default_type: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 55 | 0 | return $default_type; | |||||||||||||||||||||||||||
| 56 | 115 | }; | |||||||||||||||||||||||||||
| 57 | 20 | }; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | # To make sure type and label are always up to date with eachother | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 4 | ▶ | sub _type_set { | ||||||||||||||||||||||||||
|
Subroutine
_type_set: called CC=4 SCAR=14.5
| |||||||||||||||||||||||||||||
| 62 | 4 | my ( $self, $type ) = @_; | |||||||||||||||||||||||||||
| 63 | 4 | ▶ | if ( $type->name eq '' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | 0 | return $self->type( to_Rel( $self->default_type ) ); | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | 4 | ▶ | return if ( defined $self->label and $self->label eq $type->name ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $self->label and $self->label eq $type->name
MC/DC50%1/2
defined $self->label and $self->label eq $type->name
defined $self->label
$self->label eq $type->name
Truth table66%2/3
A and B
A= defined $self->labelB= $self->label eq $type->name
| |||||||||||||||||||||||||||||
| 67 | 1 | $self->label( $type->name ); | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 3 | ▶ | sub _label_set { | ||||||||||||||||||||||||||
|
Subroutine
_label_set: called CC=4 SCAR=14.5
| |||||||||||||||||||||||||||||
| 71 | 3 | my ( $self, $label ) = @_; | |||||||||||||||||||||||||||
| 72 | 3 | ▶ | if ( $label eq '' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 0 | return $self->label( $self->default_type ); | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | 3 | ▶ | return if ( defined $self->type and $self->type->name eq $label ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $self->type and $self->type->name eq $label
MC/DC50%1/2
defined $self->type and $self->type->name eq $label
defined $self->type
$self->type->name eq $label
Truth table66%2/3
A and B
A= defined $self->typeB= $self->type->name eq $label
| |||||||||||||||||||||||||||||
| 76 | 2 | $self->type($label); | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 20 | ▶ | no Moose::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||