| 1 | package Math::Expression::Evaluator::Util; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | =head1 NAME | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | Math::Expression::Evaluator::Util - Common functions for | ||||||||||||||||||||||||||||
| 6 | Math::Expression::Evaluator | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | =head1 SYNPOSIS | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | use Math::Expression::Evaluator::Util qw(is_lvalue); | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | # ... | ||||||||||||||||||||||||||||
| 13 | if (is_lvalue($ast)){ | ||||||||||||||||||||||||||||
| 14 | # $ast represents an lvalue, at the moment just a variable | ||||||||||||||||||||||||||||
| 15 | } | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | This is package with common functions used in the different modules in | ||||||||||||||||||||||||||||
| 20 | the Math::Expression::Evaluator distribution. | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | =over | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | =item is_lvalue | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | C<is_lvalue($ast)> checks if (a simplified version of) C<$ast> represents | ||||||||||||||||||||||||||||
| 27 | something that can be assigned to, i.e. is a variable. | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | =back | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | =cut | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 17 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 34 | 17 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 17 | require Exporter; | |||||||||||||||||||||||||||
| 37 | 17 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||
| 38 | 17 | our @EXPORT_OK = qw(is_lvalue); | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | # checks if the given AST represents a lvalue of an _assignment | ||||||||||||||||||||||||||||
| 41 | 16 | ▶ | sub is_lvalue { | ||||||||||||||||||||||||||
|
Subroutine
is_lvalue: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 42 | 16 | my $ast = shift; | |||||||||||||||||||||||||||
| 43 | 16 | ▶ | if (ref($ast) && $ast->[0] eq '$'){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $ast and $ast->[0] eq "\$"
MC/DC100%2/2
ref $ast and $ast->[0] eq "\$"
ref $ast
$ast->[0] eq "\$"
Truth table100%3/3
A and B
A= ref $astB= $ast->[0] eq "\$"
| |||||||||||||||||||||||||||||
| 44 | # simple variable name | ||||||||||||||||||||||||||||
| 45 | 13 | return 1; | |||||||||||||||||||||||||||
| 46 | } else { | ||||||||||||||||||||||||||||
| 47 | 3 | return 0; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 17 | 1; | |||||||||||||||||||||||||||
| 52 | # vim: sw=4 ts=4 expandtab | ||||||||||||||||||||||||||||