1Perl6::Junction(3) User Contributed Perl Documentation Perl6::Junction(3)
2
3
4
6 Perl6::Junction - Perl6 style Junction operators in Perl5.
7
9 use Perl6::Junction qw/ all any none one /;
10
11 if (any(@grant) eq 'su') {
12 ...
13 }
14
15 if (all($foo, $bar) >= 10) {
16 ...
17 }
18
19 if (qr/^\d+$/ == all(@answers)) {
20 ...
21 }
22
23 if (all(@input) <= @limits) {
24 ...
25 }
26
27 if (none(@pass) eq 'password') {
28 ...
29 }
30
31 if (one(@answer) == 42) {
32 ...
33 }
34
36 This is a lightweight module which provides 'Junction' operators, the
37 most commonly used being "any" and "all".
38
39 Inspired by the Perl6 design docs,
40 <http://dev.perl.org/perl6/doc/design/exe/E06.html>.
41
42 Provides a limited subset of the functionality of
43 Quantum::Superpositions, see "SEE ALSO" for comment.
44
45 Notice in the "SYNOPSIS" above, that if you want to match against a
46 regular expression, you must use "==" or "!=". Not "=~" or "!~". You
47 must also use a regex object, such as "qr/\d/", not a plain regex such
48 as "/\d/".
49
51 all()
52 Returns an object which overloads the following operators:
53
54 '<', '<=', '>', '>=', '==', '!=',
55 'lt', 'le', 'gt', 'ge', 'eq', 'ne',
56
57 Returns true only if all arguments test true according to the operator
58 used.
59
60 any()
61 Returns an object which overloads the following operators:
62
63 '<', '<=', '>', '>=', '==', '!=',
64 'lt', 'le', 'gt', 'ge', 'eq', 'ne',
65
66 Returns true if any argument tests true according to the operator used.
67
68 none()
69 Returns an object which overloads the following operators:
70
71 '<', '<=', '>', '>=', '==', '!=',
72 'lt', 'le', 'gt', 'ge', 'eq', 'ne',
73
74 Returns true only if no argument tests true according to the operator
75 used.
76
77 one()
78 Returns an object which overloads the following operators:
79
80 '<', '<=', '>', '>=', '==', '!=',
81 'lt', 'le', 'gt', 'ge', 'eq', 'ne',
82
83 Returns true only if one and only one argument tests true according to
84 the operator used.
85
87 You cannot alter junctions. Instead, you can create new junctions out
88 of old junctions. You can do this by calling the "values" method on a
89 junction.
90
91 my $numbers = any(qw/1 2 3 4 5/);
92 print $numbers == 3 ? 'Yes' : 'No'; # Yes
93
94 $numbers = any( grep { $_ != 3 } $numbers->values );
95 print $numbers == 3 ? 'Yes' : 'No'; # No
96
98 'all', 'any', 'none', 'one', as requested.
99
100 All subroutines can be called by its fully qualified name, if you don't
101 want to export them.
102
103 use Perl6::Junction;
104
105 if (Perl6::Junction::any( @questions )) {
106 ...
107 }
108
110 When comparing against a regular expression, you must remember to use a
111 regular expression object: "qr/\d/" Not "/d/". You must also use either
112 "==" or "!=". This is because "=~" and "!~" cannot be overriden.
113
115 Add overloading for arithmetic operators, such that this works:
116
117 $result = any(2,3,4) * 2;
118
119 if ($result == 8) {...}
120
122 Submit to the CPAN bugtracker <http://rt.cpan.org>
123
125 Quantum::Superpositions provides the same functionality as this, and
126 more. However, this module provides this limited functionality at a
127 much greater runtime speed, with my benchmarks showing between 500% and
128 6000% improvment.
129
130 <http://dev.perl.org/perl6/doc/design/exe/E06.html> - "The Wonderful
131 World of Junctions".
132
134 Carl Franks
135
137 Thanks to "Curtis "Ovid" Poe" for the "ALTERING JUNCTIONS" changes in
138 release 0.40000.
139
141 Copyright 2005, Carl Franks. All rights reserved.
142
143 This library is free software; you can redistribute it and/or modify it
144 under the same terms as Perl itself (perlgpl, perlartistic).
145
146
147
148perl v5.32.0 2020-07-28 Perl6::Junction(3)