1Syntax::Keyword::JunctiUosne(r3)Contributed Perl DocumenStyanttiaoxn::Keyword::Junction(3)
2
3
4

NAME

6       Syntax::Keyword::Junction - Perl6 style Junction operators in Perl5
7

VERSION

9       version 0.003008
10

SYNOPSIS

12         use Syntax::Keyword::Junction qw/ all any none one /;
13
14         if (any(@grant) eq 'su') {
15           ...
16         }
17
18         if (all($foo, $bar) >= 10) {
19           ...
20         }
21
22         if (qr/^\d+$/ == all(@answers)) {
23           ...
24         }
25
26         if (all(@input) <= @limits) {
27           ...
28         }
29
30         if (none(@pass) eq 'password') {
31           ...
32         }
33
34         if (one(@answer) == 42) {
35           ...
36         }
37
38       or if you want to rename an export, use Sub::Exporter options:
39
40         use Syntax::Keyword::Junction any => { -as => 'robot_any' };
41
42         if (robot_any(@grant) eq 'su') {
43           ...
44         }
45

DESCRIPTION

47       This is a lightweight module which provides 'Junction' operators, the
48       most commonly used being "any" and "all".
49
50       Inspired by the Perl6 design docs,
51       <http://dev.perl.org/perl6/doc/design/exe/E06.html>.
52
53       Provides a limited subset of the functionality of
54       Quantum::Superpositions, see "SEE ALSO" for comment.
55
56       Notice in the "SYNOPSIS" above, that if you want to match against a
57       regular expression, you must use "==" or "!=". Not "=~" or "!~". You
58       must also use a regex object, such as "qr/\d/", not a plain regex such
59       as "/\d/".
60

SUBROUTINES

62   all()
63       Returns an object which overloads the following operators:
64
65         '<',  '<=', '>',  '>=', '==', '!=',
66         'lt', 'le', 'gt', 'ge', 'eq', 'ne',
67         '~~'
68
69       Returns true only if all arguments test true according to the operator
70       used.
71
72   any()
73       Returns an object which overloads the following operators:
74
75         '<',  '<=', '>',  '>=', '==', '!=',
76         'lt', 'le', 'gt', 'ge', 'eq', 'ne',
77         '~~'
78
79       Returns true if any argument tests true according to the operator used.
80
81   none()
82       Returns an object which overloads the following operators:
83
84         '<',  '<=', '>',  '>=', '==', '!=',
85         'lt', 'le', 'gt', 'ge', 'eq', 'ne',
86         '~~'
87
88       Returns true only if no argument tests true according to the operator
89       used.
90
91   one()
92       Returns an object which overloads the following operators:
93
94         '<',  '<=', '>',  '>=', '==', '!=',
95         'lt', 'le', 'gt', 'ge', 'eq', 'ne',
96         '~~'
97
98       Returns true only if one and only one argument tests true according to
99       the operator used.
100

ALTERING JUNCTIONS

102       You cannot alter junctions.  Instead, you can create new junctions out
103       of old junctions.  You can do this by calling the "values" method on a
104       junction.
105
106        my $numbers = any(qw/1 2 3 4 5/);
107        print $numbers == 3 ? 'Yes' : 'No';   # Yes
108
109        $numbers = any( grep { $_ != 3 } $numbers->values );
110        print $numbers == 3 ? 'Yes' : 'No';   # No
111
112       You can also use the "map" method:
113
114        my $numbers = any(qw/1 2 3 4 5/);
115        my $prime   = $numbers->map( \&is_prime );
116
117        say for $prime->values; # prints 0, 1, 1, 0, 1
118

EXPORT

120       'all', 'any', 'none', 'one', as requested.
121
122       All subroutines can be called by its fully qualified name, if you don't
123       want to export them.
124
125         use Syntax::Keyword::Junction;
126
127         if (Syntax::Keyword::Junction::any( @questions )) {
128           ...
129         }
130

WARNING

132       When comparing against a regular expression, you must remember to use a
133       regular expression object: "qr/\d/" Not "/d/". You must also use either
134       "==" or "!=". This is because "=~" and "!~" cannot be overridden.
135

TO DO

137       Add overloading for arithmetic operators, such that this works:
138
139         $result = any(2,3,4) * 2;
140
141         if ($result == 8) {...}
142

SEE ALSO

144       This module is actually a fork of Perl6::Junction with very few
145       (initial) changes.  The reason being that we want to avoid the
146       incendiary name containing Perl6.
147
148       Quantum::Superpositions provides the same functionality as this, and
149       more. However, this module provides this limited functionality at a
150       much greater runtime speed, with my benchmarks showing between 500% and
151       6000% improvement.
152
153       <http://dev.perl.org/perl6/doc/design/exe/E06.html> - "The Wonderful
154       World of Junctions".
155

AUTHORS

157       •   Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com>
158
159       •   Carl Franks
160
162       This software is copyright (c) 2014 by Arthur Axel "fREW" Schmidt.
163
164       This is free software; you can redistribute it and/or modify it under
165       the same terms as the Perl 5 programming language system itself.
166
167
168
169perl v5.34.0                      2022-01-21      Syntax::Keyword::Junction(3)
Impressum