| 1 | package Mason::Plugin::SliceFilter::Filters::Slice; | ||||||||||||||||||||||||||||
| 2 | ## So we can access Mason::Request->current_request | ||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use Mason::Request; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | extends qw/Mason::DynamicFilter/; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 15 | ▶ | has 'get_slice' => ( is => 'ro' , isa => 'CodeRef' , required => 1 , default => sub{my $self = shift; return sub{ my $param = shift ; $self->m->request_args()->{$param} }; } ); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 23 | ▶ | has 'm' => ( is => 'ro' , isa => 'Mason::Request' , required => 1 , default => sub{ return Mason::Request->current_request();}); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | has 'slice_id' => ( is => 'ro' , isa => 'Str' , required => 1 ); | |||||||||||||||||||||||||||
| 10 | 2 | has 'slice_param' => ( is => 'ro', isa => 'Str', required => 1 , default => 'slice' ); | |||||||||||||||||||||||||||
| 11 | 2 | has 'can_skip' => ( is => 'ro', isa => 'Bool', required => 1 , default => 0 ); | |||||||||||||||||||||||||||
| 12 | 2 | has 'yield_noslice' => ( is => 'ro' , isa => 'Bool', required => 1 , default => 1 ); | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | has '+filter' => | ||||||||||||||||||||||||||||
| 15 | ( default => | ||||||||||||||||||||||||||||
| 16 | 23 | ▶ | sub{ | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 23 | my ($self) = @_; | |||||||||||||||||||||||||||
| 18 | 23 | ▶ | sub{ | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||
| 19 | 23 | my ($yield) = @_; | |||||||||||||||||||||||||||
| 20 | 23 | my $m = $self->m(); | |||||||||||||||||||||||||||
| 21 | 23 | my $slice_param = &{$self->get_slice()}($self->slice_param()); | |||||||||||||||||||||||||||
| 22 | ## warn "GOT SLICE PARAM '$slice_param'"; | ||||||||||||||||||||||||||||
| 23 | 23 | ▶ | unless(length($slice_param // '' ) ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$slice_param // ""
MC/DC100%1/1
$slice_param // ""
$slice_param
Truth table100%2/2
A
A= $slice_param
| |||||||||||||||||||||||||||||
| 24 | 3 | ▶ | if( $self->yield_noslice() ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | ## warn "NO SLICE PARAM. Yielding"; | ||||||||||||||||||||||||||||
| 26 | 2 | return ( $yield->() ); | |||||||||||||||||||||||||||
| 27 | }else{ | ||||||||||||||||||||||||||||
| 28 | 1 | return ''; | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | }else{ | ||||||||||||||||||||||||||||
| 31 | ## warn "We have a slice $slice_param"; | ||||||||||||||||||||||||||||
| 32 | 20 | ▶ | if( $slice_param eq $self->slice_id ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | ## warn "SLICE HIT on $slice_param!"; | ||||||||||||||||||||||||||||
| 34 | ## Flush any previously generated content | ||||||||||||||||||||||||||||
| 35 | 11 | $m->clear_buffer(); | |||||||||||||||||||||||||||
| 36 | # Record the fact we have a slice hit | ||||||||||||||||||||||||||||
| 37 | # That will prevent nested 'can_skip' slices to | ||||||||||||||||||||||||||||
| 38 | # skip their output. | ||||||||||||||||||||||||||||
| 39 | 11 | $m->notes(__PACKAGE__.'_slicehit' , 1); | |||||||||||||||||||||||||||
| 40 | 11 | $m->out_method->(($yield->()), $m ); | |||||||||||||||||||||||||||
| 41 | 11 | $m->flush_buffer(); | |||||||||||||||||||||||||||
| 42 | 11 | $m->abort(); | |||||||||||||||||||||||||||
| 43 | ## Job done | ||||||||||||||||||||||||||||
| 44 | }else{ | ||||||||||||||||||||||||||||
| 45 | ## warn "SLICE MISS on $slice_param"; | ||||||||||||||||||||||||||||
| 46 | 9 | ▶ | unless( $self->can_skip() && !$m->notes(__PACKAGE__.'_slicehit') ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->can_skip and not $m->notes("Mason::Plugin::SliceFilter::Filters::Slice_slicehit")
MC/DC100%2/2
$self->can_skip and not $m->notes("Mason::Plugin::SliceFilter::Filters::Slice_slicehit")
$self->can_skip
not $m->notes("Mason::Plugin::SliceFilter::Filters::Slice_slicehit")
Truth table100%3/3
A and not(B)
A= $self->can_skipB= not $m->notes("Mason::Plugin::SliceFilter::Filters::Slice_slicehit")
| |||||||||||||||||||||||||||||
| 47 | 8 | return ( $yield->() ); | |||||||||||||||||||||||||||
| 48 | }else{ | ||||||||||||||||||||||||||||
| 49 | 1 | return ''; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | 23 | }); | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 2 | __PACKAGE__->meta->make_immutable(); | |||||||||||||||||||||||||||
| 57 | __END__ | ||||||||||||||||||||||||||||