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