| 1 | package Petal::Utils::If; | ||||||||||||
| 2 | |||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 4 | ▶ | use warnings::register; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | |||||||||||||
| 6 | 4 | ▶ | use Carp; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | |||||||||||||
| 8 | 4 | ▶ | use base qw( Petal::Utils::Base ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | |||||||||||||
| 10 | 4 | ▶ | use constant name => 'if'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | 4 | ▶ | use constant aliases => qw(); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | |||||||||||||
| 13 | 4 | our $VERSION = ((require Petal::Utils), $Petal::Utils::VERSION)[1]; | |||||||||||
| 14 | 4 | our $REVISION = (split(/ /, ' $Revision: 1.2 $ '))[2]; | |||||||||||
| 15 | |||||||||||||
| 16 | 2 | ▶ | sub process { | ||||||||||
|
Subroutine
process: called CC=7 SCAR=20.8
Pod
undocumented
| |||||||||||||
| 17 | 2 | my $class = shift; | |||||||||||
| 18 | 2 | my $hash = shift; | |||||||||||
| 19 | 2 | ▶ | my $args = shift || confess( "'if' expects args of the form 'if: ... then: ... [else: ...]' (got nothing)!" ); | ||||||||||
|
Condition50%1/2
shift() || confess(q['if' expects args of the form 'if: ... then: ... [else: ...]' (got nothing)!])
MC/DC0%0/1
shift() || confess(q['if' expects args of the form 'if: ... then: ... [else: ...]' (got nothing)!])
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||
| 20 | |||||||||||||
| 21 | 2 | my @args = $args =~ /\A(.+?)\sthen:\s+(.+?)(?:\s+else:\s+(.+?))?\z/; | |||||||||||
| 22 | 2 | ▶ | confess( "'if' expects arguments of the form: 'if: ... then: ... [else: ...]', not 'if: $args'!" ) unless @args; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 23 | 2 | ▶ | $args[0] || confess( "1st arg to 'if' should be an expression (got nothing)!" ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 24 | 2 | ▶ | $args[1] || confess( "2nd arg to 'if' (after then:) should be an expression (got nothing)!" ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 25 | |||||||||||||
| 26 | 2 | ▶ | return $hash->fetch($args[1]) if $hash->fetch($args[0]); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 27 | 1 | ▶ | return $hash->fetch($args[2]) if $args[2]; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 28 | 0 | return ''; | |||||||||||
| 29 | } | ||||||||||||
| 30 | |||||||||||||
| 31 | 4 | 1; | |||||||||||