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".


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).


Return truthy if the NameSet contains the argument. Usage: $set->contains('foo').

smartmatch overload

For convenience, 'foo' ~~ $nameset invokes $nameset->contains('foo'). This is inspired by the Raku behaviour, in which $x ~~ $y calls $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 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.