| 1 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 2 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | |||
| 4 | package Cond::Expr; # git description: 0.04-25-gb42799c | ||
| 5 | # ABSTRACT: Conditionals as expressions | ||
| 6 | |||
| 7 | 1 | our $VERSION = '0.05'; | |
| 8 | |||
| 9 | 1 | ▶ | use Sub::Exporter -setup => { |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | exports => ['cond'], | ||
| 11 | groups => { default => ['cond'] }, | ||
| 12 | 1 | }; | |
| 13 | |||
| 14 | 1 | ▶ | use Devel::CallParser; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 15 | 1 | ▶ | use Devel::CallChecker; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 16 | |||
| 17 | 1 | ▶ | use XSLoader; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 18 | |||
| 19 | 1 | XSLoader::load( | |
| 20 | __PACKAGE__, | ||
| 21 | $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<cond> control structure. | ||
| 38 | #pod | ||
| 39 | #pod =head2 How is this different from… | ||
| 40 | #pod | ||
| 41 | #pod =over 4 | ||
| 42 | #pod | ||
| 43 | #pod =item * C<given>/C<when> | ||
| 44 | #pod | ||
| 45 | #pod C<given> 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<do> block, which | ||
| 47 | #pod is cumbersome. | ||
| 48 | #pod | ||
| 49 | #pod Additionally, this module avoids all the, possibly unwanted, side effects | ||
| 50 | #pod C<given>/C<when> and its underlying smart matching mechanism happen to impose. | ||
| 51 | #pod | ||
| 52 | #pod =item * C<if>/C<elsif>/C<else> | ||
| 53 | #pod | ||
| 54 | #pod Similar to C<given>, C<if> 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 ( | ||
| 64 | #pod ($answer == 42) ? (answer => $answer) | ||
| 65 | #pod : ($answer) ? (wrong_answer => 1) | ||
| 66 | #pod : (no_answer => 1) | ||
| 67 | #pod ), | ||
| 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</SYNOPSIS> for this module | ||
| 72 | #pod will compile into. The main difference is the C<cond> syntax provided by this | ||
| 73 | #pod module being easier on the eye. | ||
| 74 | #pod | ||
| 75 | #pod =back | ||
| 76 | #pod | ||
| 77 | #pod =func C<cond> | ||
| 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<cond> 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<undef> 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 | 1; | |
| 93 | |||
| 94 | __END__ | ||