| 1 | package Data::Frame::Partial::Sugar; | ||||||||||||||
| 2 | 11 | $Data::Frame::Partial::Sugar::VERSION = '0.006005'; | |||||||||||||
| 3 | # ABSTRACT: Partial class for data frame syntax sugar | ||||||||||||||
| 4 | |||||||||||||||
| 5 | 11 | ▶ | use Data::Frame::Role; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | 11 | ▶ | use namespace::autoclean; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | |||||||||||||||
| 8 | 11 | package Tie::Data::Frame { | |||||||||||||
| 9 | 11 | $Tie::Data::Frame::VERSION = '0.006005'; | |||||||||||||
| 10 | |||||||||||||||
| 11 | 11 | ▶ | use Scalar::Util qw(weaken); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | 11 | ▶ | use Types::PDL qw(Piddle); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 13 | 11 | ▶ | use Types::Standard qw(ArrayRef Value); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 14 | 11 | ▶ | use Type::Params; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 15 | |||||||||||||||
| 16 | 323 | ▶ | sub new { | ||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
| |||||||||||||||
| 17 | 323 | my ($class, $object) = @_; | |||||||||||||
| 18 | 323 | my $self = bless( { _object => $object }, $class); | |||||||||||||
| 19 | 323 | weaken( $self->{_object} ); | |||||||||||||
| 20 | 323 | return $self; | |||||||||||||
| 21 | } | ||||||||||||||
| 22 | |||||||||||||||
| 23 | 323 | ▶ | sub TIEHASH { | ||||||||||||
|
Subroutine
TIEHASH: called CC=1 SCAR=0.0
| |||||||||||||||
| 24 | 323 | my $class = shift; | |||||||||||||
| 25 | 323 | return $class->new(@_); | |||||||||||||
| 26 | } | ||||||||||||||
| 27 | |||||||||||||||
| 28 | 6 | ▶ | sub object { $_[0]->{_object} } | ||||||||||||
|
Subroutine
object: called CC=1 SCAR=0.0
| |||||||||||||||
| 29 | |||||||||||||||
| 30 | 5 | ▶ | sub _check_key { | ||||||||||||
|
Subroutine
_check_key: called CC=1 SCAR=0.0
| |||||||||||||||
| 31 | 5 | my $self = shift; | |||||||||||||
| 32 | 5 | state $check = Type::Params::compile(Value | ArrayRef | Piddle); | |||||||||||||
| 33 | 5 | my ($key) = $check->(@_); | |||||||||||||
| 34 | 5 | return $key; | |||||||||||||
| 35 | } | ||||||||||||||
| 36 | |||||||||||||||
| 37 | 1 | ▶ | sub STORE { | ||||||||||||
|
Subroutine
STORE: called CC=2 SCAR=7.4
| |||||||||||||||
| 38 | 1 | my ( $self, $key, $val ) = @_; | |||||||||||||
| 39 | 1 | $key = $self->_check_key($key); | |||||||||||||
| 40 | |||||||||||||||
| 41 | 1 | ▶ | if ( Ref::Util::is_ref($key) ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 42 | 0 | $self->object->slice($key) .= $val; | |||||||||||||
| 43 | } else { | ||||||||||||||
| 44 | 1 | $self->object->set($key, $val); | |||||||||||||
| 45 | } | ||||||||||||||
| 46 | } | ||||||||||||||
| 47 | |||||||||||||||
| 48 | 4 | ▶ | sub FETCH { | ||||||||||||
|
Subroutine
FETCH: called CC=2 SCAR=6.9
| |||||||||||||||
| 49 | 4 | my ( $self, $key ) = @_; | |||||||||||||
| 50 | 4 | $key = $self->_check_key($key); | |||||||||||||
| 51 | |||||||||||||||
| 52 | 4 | ▶ | if ( Ref::Util::is_ref($key) ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 53 | 2 | return $self->object->slice($key); | |||||||||||||
| 54 | } else { | ||||||||||||||
| 55 | 2 | return $self->object->at($key); | |||||||||||||
| 56 | } | ||||||||||||||
| 57 | } | ||||||||||||||
| 58 | |||||||||||||||
| 59 | 0 | ▶ | sub EXISTS { | ||||||||||||
|
Subroutine
EXISTS: not called CC=1 SCAR=6.9
| |||||||||||||||
| 60 | 0 | my ($self, $key) = @_; | |||||||||||||
| 61 | 0 | return $self->object->exists($key); | |||||||||||||
| 62 | } | ||||||||||||||
| 63 | |||||||||||||||
| 64 | 1 | ▶ | sub FIRSTKEY { | ||||||||||||
|
Subroutine
FIRSTKEY: called CC=1 SCAR=0.0
| |||||||||||||||
| 65 | 1 | my ($self) = @_; | |||||||||||||
| 66 | 1 | $self->{_list} = [ @{$self->object->names} ]; | |||||||||||||
| 67 | 1 | return $self->NEXTKEY; | |||||||||||||
| 68 | } | ||||||||||||||
| 69 | |||||||||||||||
| 70 | 12 | ▶ | sub NEXTKEY { | ||||||||||||
|
Subroutine
NEXTKEY: called CC=1 SCAR=0.0
| |||||||||||||||
| 71 | 12 | my ($self) = @_; | |||||||||||||
| 72 | 12 | return shift @{$self->{_list}}; | |||||||||||||
| 73 | } | ||||||||||||||
| 74 | } | ||||||||||||||
| 75 | |||||||||||||||
| 76 | 11 | ▶ | use overload ( | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 77 | 471 | ▶ | '%{}' => sub { # for working with Tie::Data::Frame | ||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.2
| |||||||||||||||
| 78 | 471 | my ($self) = @_; | |||||||||||||
| 79 | |||||||||||||||
| 80 | # This is brittle as we are depending on an private thing of Moo... | ||||||||||||||
| 81 | 471 | my ($caller) = caller(); | |||||||||||||
| 82 | 471 | ▶ | if ( $caller eq 'Method::Generate::Accessor::_Generated' ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 83 | 0 | return $self; | |||||||||||||
| 84 | } | ||||||||||||||
| 85 | 471 | my $tmp = $self->_tie_hash; # avoid // as breaks Devel::Cover | |||||||||||||
| 86 | 471 | ▶ | $tmp = $self if !defined $tmp; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 87 | 471 | $tmp; | |||||||||||||
| 88 | }, | ||||||||||||||
| 89 | 11 | fallback => 1 | |||||||||||||
| 90 | 11 | ); | |||||||||||||
| 91 | |||||||||||||||
| 92 | 11 | has _tie_hash => ( is => 'rw' ); | |||||||||||||
| 93 | |||||||||||||||
| 94 | 323 | ▶ | method _initialize_sugar() { | ||||||||||||
|
Subroutine
_initialize_sugar: called CC=3 SCAR=11.2
Branch: 2 branches
| |||||||||||||||
| 95 | 323 | my %hash; | |||||||||||||
| 96 | 323 | tie %hash, qw(Tie::Data::Frame), $self; | |||||||||||||
| 97 | 323 | $self->_tie_hash( \%hash ); | |||||||||||||
| 98 | 11 | } | |||||||||||||
| 99 | |||||||||||||||
| 100 | 11 | 1; | |||||||||||||
| 101 | |||||||||||||||
| 102 | __END__ | ||||||||||||||