| 1 | 6 | ▶ | use 5.008; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 2 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 3 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||
| 5 | package Tie::Moose; | ||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||
| 7 | 6 | our $AUTHORITY = 'cpan:TOBYINK'; | |||||||||||||||||||||||||||||||||||||
| 8 | 6 | our $VERSION = '0.003'; | |||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||
| 10 | 6 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 11 | 6 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 12 | 6 | ▶ | use Carp qw( croak ); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 13 | 6 | ▶ | use Types::Standard -types; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||
| 15 | 6 | with 'MooseX::Traits'; | |||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||
| 17 | 6 | has object => ( | |||||||||||||||||||||||||||||||||||||
| 18 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||
| 19 | isa => Object, | ||||||||||||||||||||||||||||||||||||||
| 20 | required => 1, | ||||||||||||||||||||||||||||||||||||||
| 21 | ); | ||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||
| 23 | 6 | has attributes => ( | |||||||||||||||||||||||||||||||||||||
| 24 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||
| 25 | isa => ArrayRef[ ArrayRef[ Maybe[Str] ] ], | ||||||||||||||||||||||||||||||||||||||
| 26 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||
| 27 | builder => '_build_attributes', | ||||||||||||||||||||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||
| 30 | 6 | has attributes_hash => ( | |||||||||||||||||||||||||||||||||||||
| 31 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||
| 32 | isa => HashRef[ ArrayRef[ Maybe[Str] ] ], | ||||||||||||||||||||||||||||||||||||||
| 33 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||
| 34 | builder => '_build_attributes_hash', | ||||||||||||||||||||||||||||||||||||||
| 35 | ); | ||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||
| 37 | 6 | has "+_trait_namespace" => ( | |||||||||||||||||||||||||||||||||||||
| 38 | default => __PACKAGE__, | ||||||||||||||||||||||||||||||||||||||
| 39 | ); | ||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||
| 41 | sub _build_attributes | ||||||||||||||||||||||||||||||||||||||
| 42 | 5 | ▶ | { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_attributes: called CC=3 SCAR=11.7
| |||||||||||||||||||||||||||||||||||||||
| 43 | return [ | ||||||||||||||||||||||||||||||||||||||
| 44 | 5 | ▶ | map [ | ||||||||||||||||||||||||||||||||||||
|
Condition66%4/6
$_->reader || $_->accessor
$_->writer || $_->accessor
MC/DC0%0/2
$_->reader || $_->accessor
$_->reader
$_->accessor
MC/DC50%1/2
$_->writer || $_->accessor
$_->writer
$_->accessor
Truth table66%2/3
A || B
A= $_->readerB= $_->accessor
Truth table66%2/3
A || B
A= $_->writerB= $_->accessor
| |||||||||||||||||||||||||||||||||||||||
| 45 | $_->name, # 0 | ||||||||||||||||||||||||||||||||||||||
| 46 | $_->reader || $_->accessor, # 1 | ||||||||||||||||||||||||||||||||||||||
| 47 | $_->writer || $_->accessor, # 2 | ||||||||||||||||||||||||||||||||||||||
| 48 | $_->predicate, # 3 | ||||||||||||||||||||||||||||||||||||||
| 49 | $_->clearer, # 4 | ||||||||||||||||||||||||||||||||||||||
| 50 | ], Class::MOP::class_of(shift->object)->get_all_attributes | ||||||||||||||||||||||||||||||||||||||
| 51 | ] | ||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||
| 54 | sub _build_attributes_hash | ||||||||||||||||||||||||||||||||||||||
| 55 | 5 | ▶ | { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_attributes_hash: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 56 | 5 | return +{ map {; $_->[0], $_ } @{ shift->attributes } }; | |||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||
| 59 | sub fallback | ||||||||||||||||||||||||||||||||||||||
| 60 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
fallback: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 61 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 62 | 2 | my ($operation, $key) = @_; | |||||||||||||||||||||||||||||||||||||
| 63 | 2 | croak "No attribute '$key' in tied object"; | |||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||
| 66 | sub TIEHASH | ||||||||||||||||||||||||||||||||||||||
| 67 | 6 | ▶ | { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
TIEHASH: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 68 | 6 | my $class = shift; | |||||||||||||||||||||||||||||||||||||
| 69 | 6 | my ($object, %opts) = @_; | |||||||||||||||||||||||||||||||||||||
| 70 | 6 | $class->new(%opts, object => $object); | |||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||
| 73 | sub FETCH | ||||||||||||||||||||||||||||||||||||||
| 74 | 18 | ▶ | { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
FETCH: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||
| 75 | 18 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 76 | 18 | my ($key) = @_; | |||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||
| 78 | 18 | ▶ | $self->attributes_hash->{$key} | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 79 | or return $self->fallback(FETCH => $key); | ||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||
| 81 | 15 | ▶ | my $accessor = $self->attributes_hash->{$key}[1] | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 82 | or croak "No reader for attribute '$key' in tied object"; | ||||||||||||||||||||||||||||||||||||||
| 83 | 15 | return $self->object->$accessor; | |||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||
| 86 | sub STORE | ||||||||||||||||||||||||||||||||||||||
| 87 | 12 | ▶ | { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
STORE: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||
| 88 | 12 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 89 | 12 | my ($key, $value) = @_; | |||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||
| 91 | 12 | ▶ | $self->attributes_hash->{$key} | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 92 | or return $self->fallback(STORE => $key, $value); | ||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||
| 94 | 9 | ▶ | my $accessor = $self->attributes_hash->{$key}[2] | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 95 | or croak "No writer for attribute '$key' in tied object"; | ||||||||||||||||||||||||||||||||||||||
| 96 | 5 | return $self->object->$accessor($value); | |||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||
| 99 | sub EXISTS | ||||||||||||||||||||||||||||||||||||||
| 100 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
EXISTS: called CC=3 SCAR=16.0
| |||||||||||||||||||||||||||||||||||||||
| 101 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 102 | 1 | my ($key) = @_; | |||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||
| 104 | 1 | ▶ | $self->attributes_hash->{$key} | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 105 | or return $self->fallback(EXISTS => $key); | ||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||
| 107 | 0 | my $accessor = $self->attributes_hash->{$key}[3]; | |||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | $accessor and return $self->object->$accessor; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||
| 110 | 0 | return $self->object->meta->find_attribute_by_name($key)->has_value($self->object); | |||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||
| 113 | sub DELETE | ||||||||||||||||||||||||||||||||||||||
| 114 | 15 | ▶ | { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
DELETE: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||
| 115 | 15 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 116 | 15 | my ($key) = @_; | |||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||
| 118 | 15 | ▶ | $self->attributes_hash->{$key} | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 119 | or return $self->fallback(DELETE => $key); | ||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||
| 121 | 12 | ▶ | my $accessor = $self->attributes_hash->{$key}[4] | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 122 | or croak "No clearer for attribute '$key' in tied object"; | ||||||||||||||||||||||||||||||||||||||
| 123 | 4 | return $self->object->$accessor; | |||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||
| 126 | sub CLEAR | ||||||||||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
CLEAR: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||
| 128 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||
| 130 | 0 | for my $attr (@{$self->attributes}) | |||||||||||||||||||||||||||||||||||||
| 131 | { | ||||||||||||||||||||||||||||||||||||||
| 132 | 0 | my $name = $attr->[0]; | |||||||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | $self->EXISTS($name) and $self->DELETE($name); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||
| 137 | sub FIRSTKEY | ||||||||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
FIRSTKEY: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||
| 139 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 140 | 0 | for my $attr (@{$self->attributes}) | |||||||||||||||||||||||||||||||||||||
| 141 | { | ||||||||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | next unless $self->EXISTS($attr->[0]); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 143 | 0 | return $attr->[0]; | |||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||
| 145 | 0 | return; | |||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||
| 148 | sub NEXTKEY | ||||||||||||||||||||||||||||||||||||||
| 149 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
NEXTKEY: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||
| 150 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 151 | 0 | my ($lastkey) = @_; | |||||||||||||||||||||||||||||||||||||
| 152 | 0 | my $should_return; | |||||||||||||||||||||||||||||||||||||
| 153 | 0 | for my $attr (@{$self->attributes}) | |||||||||||||||||||||||||||||||||||||
| 154 | { | ||||||||||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | if ($attr->[0] eq $lastkey) | ||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||
| 156 | 0 | { $should_return++; } | |||||||||||||||||||||||||||||||||||||
| 157 | elsif (not $self->EXISTS($attr->[0])) | ||||||||||||||||||||||||||||||||||||||
| 158 | 0 | { next; } | |||||||||||||||||||||||||||||||||||||
| 159 | elsif ($should_return) | ||||||||||||||||||||||||||||||||||||||
| 160 | 0 | { return $attr->[0]; } | |||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||
| 162 | 0 | return; | |||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||
| 165 | sub SCALAR | ||||||||||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
SCALAR: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 167 | 0 | shift->object; | |||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||
| 170 | 6 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||||||||||||
| 171 | 6 | 1; | |||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||
| 173 | __END__ | ||||||||||||||||||||||||||||||||||||||