| 1 | package Text::MicroMason::HasParams; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | ###################################################################### | ||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 14 | ▶ | sub defaults { | ||||||||||||||||||
|
Subroutine
defaults: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 6 | 14 | (shift)->NEXT('defaults'), params => [ {} ] | |||||||||||||||||||
| 7 | } | ||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | ###################################################################### | ||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 9 | ▶ | sub assembler_rules { | ||||||||||||||||||
|
Subroutine
assembler_rules: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 12 | 9 | my $self = shift; | |||||||||||||||||||
| 13 | 9 | $self->NEXT('assembler_rules', @_), | |||||||||||||||||||
| 14 | init_args => 'local $m->{params} = [ ( @_ == 1 ) ? $_[0] : scalar(@_) ? { @_ } : (), $m->{params} ? @{$m->{params}} : () ];'; | ||||||||||||||||||||
| 15 | } | ||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | ###################################################################### | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 41 | ▶ | sub param { | ||||||||||||||||||
|
Subroutine
param: called CC=19 SCAR=36.4
Pod
documented
| |||||||||||||||||||||
| 20 | 41 | my $self = shift; | |||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | 41 | ▶ | my @params = $self->{params} ? @{$self->{params}} : (); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 41 | ▶ | if ( scalar @_ == 0 ) { | ||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||
| 25 | return map( keys(%$_), @params ), | ||||||||||||||||||||
| 26 | 0 | ▶ | $self->{associate} ? $self->{associate}->param() : () | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | } elsif ( scalar @_ > 1 ) { | ||||||||||||||||||||
| 29 | 4 | ▶ | if ( my $associate = $self->{associate} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 30 | 0 | return $associate->param( @_ ); | |||||||||||||||||||
| 31 | } | ||||||||||||||||||||
| 32 | 4 | ▶ | $self->{params} ||= [ {} ]; | ||||||||||||||||||
|
Condition50%1/2
$self->{"params"} ||= [{}]
MC/DC0%0/1
$self->{"params"} ||= [{}]
$self->{"params"}
Truth table50%1/2
A
A= $self->{"params"}
| |||||||||||||||||||||
| 33 | 4 | ▶ | $self->{params}[0] ||= {}; | ||||||||||||||||||
|
Condition50%1/2
$self->{"params"}[0] ||= {}
MC/DC0%0/1
$self->{"params"}[0] ||= {}
$self->{"params"}[0]
Truth table50%1/2
A
A= $self->{"params"}[0]
| |||||||||||||||||||||
| 34 | 4 | my $target = $self->{params}[0]; | |||||||||||||||||||
| 35 | 4 | ▶ | if ( $self->{case_sensitive} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 36 | 0 | %$target = ( %$target, @_ ); | |||||||||||||||||||
| 37 | } else { | ||||||||||||||||||||
| 38 | 4 | my %hash = @_; | |||||||||||||||||||
| 39 | 4 | %$target = ( %$target, map { lc($_) => $hash{$_} } keys %hash ); | |||||||||||||||||||
| 40 | # warn "set params $self->{params}[0]: " , %{ $self->{params}[0] }; | ||||||||||||||||||||
| 41 | } | ||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | ▶ | } elsif ( scalar @_ == 1 and ref( $_[0] ) ) { | |||||||||||||||||||
|
Condition33%1/3
scalar @_ == 1 and ref $_[0]
MC/DC0%0/2
scalar @_ == 1 and ref $_[0]
scalar @_ == 1
ref $_[0]
Truth table33%1/3
A and B
A= scalar @_ == 1B= ref $_[0]
| |||||||||||||||||||||
| 44 | 0 | push @{$self->{params}}, shift(); | |||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | } else { | ||||||||||||||||||||
| 47 | 37 | ▶ | my $key = $self->{case_sensitive} ? shift : lc( shift ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 48 | # warn "get params $key: $#params\n"; | ||||||||||||||||||||
| 49 | 37 | foreach my $param ( @params ) { | |||||||||||||||||||
| 50 | # warn "get params $param: $key\n"; | ||||||||||||||||||||
| 51 | my $case_key = ( exists $param->{ $key } ) ? $key : | ||||||||||||||||||||
| 52 | 41 | ▶ | ( ! $self->{case_sensitive} ) ? ( grep { lc eq $key } keys %$param )[0] : undef; | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 53 | 41 | ▶ | next unless defined $case_key; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 54 | 33 | my $value = $param->{ $case_key }; | |||||||||||||||||||
| 55 | # warn "get params $param: $key ($case_key) = $value\n"; | ||||||||||||||||||||
| 56 | 33 | ▶ | return( ( ref($value) eq 'ARRAY' ) ? @$value : $value ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 57 | } | ||||||||||||||||||||
| 58 | 4 | ▶ | if ( my $associate = $self->{associate} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 59 | my $case_key = ( $self->{case_sensitive} ) ? $key : | ||||||||||||||||||||
| 60 | 0 | ▶ | ( grep { lc eq $key } $associate->param() )[0]; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 61 | 0 | return $associate->param( $case_key ); | |||||||||||||||||||
| 62 | } | ||||||||||||||||||||
| 63 | 4 | return; | |||||||||||||||||||
| 64 | } | ||||||||||||||||||||
| 65 | } | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | ###################################################################### | ||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | 2 | 1; | |||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | __END__ | ||||||||||||||||||||