| 1 | package Data::Frame::Partial::Eval; | ||||||||||||||||||||||||||||
| 2 | 11 | $Data::Frame::Partial::Eval::VERSION = '0.006005'; | |||||||||||||||||||||||||||
| 3 | # ABSTRACT: Partial class for data frame's eval method | ||||||||||||||||||||||||||||
| 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 | ▶ | use Eval::Quosure 0.001001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 11 | ▶ | use Types::Standard; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 11 | ▶ | use Data::Frame::Indexer qw(indexer_s); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 3 | ▶ | method eval_tidy ($x) { | ||||||||||||||||||||||||||
|
Subroutine
eval_tidy: called CC=8 SCAR=21.9
Pod
documented
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 15 | 3 | my $is_quosure = $x->$_DOES('Eval::Quosure'); | |||||||||||||||||||||||||||
| 16 | 3 | ▶ | if (ref($x) and not $is_quosure) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $x and not $is_quosure
MC/DC0%0/2
ref $x and not $is_quosure
ref $x
not $is_quosure
Truth table33%1/3
A and not(B)
A= ref $xB= not $is_quosure
| |||||||||||||||||||||||||||||
| 17 | 0 | return $x; | |||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 3 | ▶ | my $expr = $is_quosure ? $x->expr : $x; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | 3 | ▶ | if ( $self->exists($expr) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | 1 | return $self->column($expr); | |||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 2 | ▶ | my $quosure = $is_quosure ? $x : Eval::Quosure->new( $expr, 1 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | # If expr matches a column name in the data frame, return the column. | ||||||||||||||||||||||||||||
| 28 | my $column_vars = { | ||||||||||||||||||||||||||||
| 29 | $self->names->map( | ||||||||||||||||||||||||||||
| 30 | 22 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 31 | 22 | my $var = '$' . ( $_ =~ s/\W/_/gr ); | |||||||||||||||||||||||||||
| 32 | 22 | $var => $self->at($_); | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | 2 | )->flatten | |||||||||||||||||||||||||||
| 35 | }; | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 2 | try { | |||||||||||||||||||||||||||
| 38 | 2 | return $quosure->eval($column_vars); | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | catch ($e) { | ||||||||||||||||||||||||||||
| 41 | 1 | die qq{Error in eval_tidy('$expr', ...) : $e }; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | 11 | } | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 11 | 1; | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | __END__ | ||||||||||||||||||||||||||||