File Coverage

blib/lib/Cond/Expr.pm
Criterion Covered Total %
statement 18 18 100.0
branch n/a
condition n/a
subroutine 6 6 100.0
pod n/a
total 24 24 100.0


line stmt bran cond sub pod time code
1 1     1   18279 use strict;
  1         3  
  1         55  
2 1     1   6 use warnings;
  1         2  
  1         89  
3              
4             package Cond::Expr; # git description: 0.03-1-ge873dfc
5             # ABSTRACT: conditionals as expressions
6             $Cond::Expr::VERSION = '0.04';
7 1         15 use Sub::Exporter -setup => {
8             exports => ['cond'],
9             groups => { default => ['cond'] },
10 1     1   764 };
  1         15223  
11              
12 1     1   1310 use Devel::CallParser;
  1         3616  
  1         90  
13 1     1   11 use Devel::CallChecker;
  1         2  
  1         54  
14              
15 1     1   7 use XSLoader;
  1         2  
  1         97  
16              
17             XSLoader::load(
18             __PACKAGE__,
19             $Cond::Expr::{VERSION} ? ${ $Cond::Expr::{VERSION} } : (),
20             );
21              
22             #pod =head1 SYNOPSIS
23             #pod
24             #pod my %args = (
25             #pod foo => 'bar',
26             #pod (cond
27             #pod ($answer == 42) { answer => $answer }
28             #pod ($answer) { wrong_answer => 1 }
29             #pod otherwise { no_answer => 1 }
30             #pod ),
31             #pod );
32             #pod
33             #pod =head1 DESCRIPTION
34             #pod
35             #pod This module implements a Lisp-alike C control structure.
36             #pod
37             #pod =head2 How is this different from…
38             #pod
39             #pod =over 4
40             #pod
41             #pod =item * C/C
42             #pod
43             #pod C is a statement, not an expression, and is therefore not readily usable
44             #pod as part of an expression unless its use is wrapped within a C block, which
45             #pod is cumbersome.
46             #pod
47             #pod Additionally, this module avoids all the, possibly unwanted, side effects
48             #pod C/C and its underlying smart matching mechanism happen to impose.
49             #pod
50             #pod =item * C/C/C
51             #pod
52             #pod Similar to C, C is a statement, needing special care in order to be
53             #pod useful as part of a surrounding expression.
54             #pod
55             #pod =item * Nested ternary C
56             #pod
57             #pod Using nested ternary C expressions, such as in
58             #pod
59             #pod my %args = (
60             #pod foo => 'bar',
61             #pod (($answer == 42)
62             #pod ? (answer => $answer)
63             #pod : ($answer)
64             #pod ? (wrong_answer => 1)
65             #pod : (no_answer => 1)),
66             #pod );
67             #pod
68             #pod can be used to achieve functionality similar to what this module provides. In
69             #pod fact, the above use of C is exactly what the L for this module
70             #pod will compile into. The main difference is the C syntax provided by this
71             #pod module being easier on the eye.
72             #pod
73             #pod =back
74             #pod
75             #pod =func C
76             #pod
77             #pod Takes a set of test/expression pairs. It evaluates each test one at a time. If a test
78             #pod returns logical true, C evaluates and returns the value of the corresponding
79             #pod expression and doesn't evaluate any of the other tests or expressions. When none of the
80             #pod provided tests yield a true value, C<()> or C is returned in list and
81             #pod scalar context, respectively.
82             #pod
83             #pod =head1 PERL REQUIREMENTS
84             #pod
85             #pod Due to the particular XS interfaces being used, this module requires a minimum
86             #pod Perl version of 5.014.
87             #pod
88             #pod =cut
89              
90             1;
91              
92             __END__