Build::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:
Build::Hopen::Util::Nameset->new(...). The parameters are as "add".
Add one or more strings or regexps to the NameSet. Usage:
$instance->add(x1, x2, ...)
xn can be a scalar, regexp, arrayref (processed recursively) or hashref (the keys are added and the values are ignored).
Return truthy if the NameSet contains the argument. Usage:
'foo' ~~ $nameset invokes
$nameset->contains('foo'). This is inspired by the Raku behaviour, in which
$x ~~ $y calls
$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.
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.