Data::Hopen::Util::NameSet - set of names (strings or regexps)
NameSet stores strings and regexps, and can quickly tell you whether a given string matches one of the stored strings or regexps.
Create a new instance. Usage: Data::Hopen::Util::Nameset->new(...). The parameters are as "add".
Data::Hopen::Util::Nameset->new(...)
Add one or more strings or regexps to the NameSet. Usage:
$instance->add(x1, x2, ...)
where each xn can be a scalar, regexp, arrayref (processed recursively) or hashref (the keys are added and the values are ignored).
xn
Return truthy if the NameSet contains the argument. Usage: $set->contains('foo').
$set->contains('foo')
For convenience, 'foo' ~~ $nameset invokes $nameset->contains('foo'). This is inspired by the Raku behaviour, in which $x ~~ $y calls $y.ACCEPTS($x)
'foo' ~~ $nameset
$nameset->contains('foo')
$x ~~ $y
$y.ACCEPTS($x)
NOTE: $nameset ~~ 'foo' (object first) is officially not supported by this module. This form is possible in stable perls at least through 5.26. However, the changes (since reverted) in 5.27.7 would not have supported this form. See http://blogs.perl.org/users/leon_timmermans/2017/12/smartmatch-in-5277.html. However, as far as I can tell, even 5.27.7 would have supported the 'foo' ~~ $nameset form.
$nameset ~~ 'foo'
Accessor for the strings in the set. Returns an arrayref.
Accessor for the regexps in the set. Returns an arrayref.
Returns truthy if the nameset has any regular expressions.
(Internal) Build a regex from all the strings and regexps in the set. Returns the new regexp --- does not mutate $self.
In the current implementation, strings are matched case-sensitively. Regexps are matched with whatever flags they were compiled with.
To install Data::Hopen, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::Hopen
CPAN shell
perl -MCPAN -e shell install Data::Hopen
For more information on module installation, please visit the detailed CPAN module installation guide.