1PPIx::Regexp::Token::MoUdsiefrieCro(n3t)ributed Perl DocPuPmIexn:t:aRteigoenxp::Token::Modifier(3)
2
3
4

NAME

6       PPIx::Regexp::Token::Modifier - Represent modifiers.
7

SYNOPSIS

9        use PPIx::Regexp::Dumper;
10        PPIx::Regexp::Dumper->new( 'qr{foo}smx' )
11            ->print();
12
13       The trailing "smx" will be represented by this class.
14
15       This class also represents the whole of things like "(?ismx)". But the
16       modifiers in something like "(?i:foo)" are represented by a
17       PPIx::Regexp::Token::GroupType::Modifier.
18

INHERITANCE

20       "PPIx::Regexp::Token::Modifier" is a PPIx::Regexp::Token.
21
22       "PPIx::Regexp::Token::Modifier" is the parent of
23       PPIx::Regexp::Token::GroupType::Modifier.
24

DESCRIPTION

26       This class represents modifier characters at the end of the regular
27       expression.  For example, in "qr{foo}smx" this class would represent
28       the terminal "smx".
29
30   The "a", "aa", "d", "l", and "u" modifiers
31       The "a", "aa", "d", "l", and "u" modifiers, introduced starting in Perl
32       5.13.6, are used to force either Unicode pattern semantics ("u"),
33       locale semantics ("l") default semantics ("d" the traditional Perl
34       semantics, which can also mean 'dual' since it means Unicode if the
35       string's UTF-8 bit is on, and locale if the UTF-8 bit is off), or
36       restricted default semantics ("a"). These are mutually exclusive, and
37       only one can be asserted at a time. Asserting any of these overrides
38       the inherited value of any of the others. The "asserted()" method
39       reports as asserted the last one it sees, or none of them if it has
40       seen none.
41
42       For example, given "PPIx::Regexp::Token::Modifier" $elem representing
43       the invalid regular expression fragment "(?dul)", "$elem->asserted( 'l'
44       )" would return true, but "$elem->asserted( 'u' )" would return false.
45       Note that "$elem->negated( 'u' )" would also return false, since "u" is
46       not explicitly negated.
47
48       If $elem represented regular expression fragment "(?i)",
49       "$elem->asserted( 'd' )" would return false, since even though "d"
50       represents the default behavior it is not explicitly asserted.
51
52   The caret ("^") modifier
53       Calling "^" a modifier is a bit of a misnomer. The "(?^...)"
54       construction was introduced in Perl 5.13.6, to prevent the inheritance
55       of modifiers. The documentation calls the caret a shorthand equivalent
56       for "d-imsx", and that it the way this class handles it.
57
58       For example, given "PPIx::Regexp::Token::Modifier" $elem representing
59       regular expression fragment "(?^i)", "$elem->asserts( 'd' )" would
60       return true, since in the absence of an explicit "l" or "u" this class
61       considers the "^" to explicitly assert "d".
62
63       The caret handling is complicated by the fact that the 'n' modifier was
64       introduced in 5.21.8, at which point the caret became equivalent to
65       "d-imnsx". I did not feel I could unconditionally add the "-n" to the
66       expansion of the caret, because that would produce confusing output
67       from methods like explain(). Nor could I make it conditional on the
68       minimum perl version, because that information is not available early
69       enough in the parse. What I did was to expand the caret into "d-imnsx"
70       if and only if 'n' was in effect at some point in the scope in which
71       the modifier was parsed.
72
73       Continuing the above example, "$elem->asserts( 'n' )" and
74       "$elem->modifier_asserted( 'n' )" would both return false, but
75       "$elem->negates( 'n' )" would return true if and only if the "/m"
76       modifier has been asserted somewhere before and in-scope from this
77       token. The modifier_asserted( 'n' ) method is inherited from
78       PPIx::Regexp::Element.
79

METHODS

81       This class provides the following public methods. Methods not
82       documented here are private, and unsupported in the sense that the
83       author reserves the right to change or remove them without notice.
84
85   asserts
86        $token->asserts( 'i' ) and print "token asserts i";
87        foreach ( $token->asserts() ) { print "token asserts $_\n" }
88
89       This method returns true if the token explicitly asserts the given
90       modifier. The example would return true for the modifier in "(?i:foo)",
91       but false for "(?-i:foo)".
92
93       Starting with version 0.036_01, if the argument is a single-character
94       modifier followed by an asterisk (intended as a wild card character),
95       the return is the number of times that modifier appears. In this case
96       an exception will be thrown if you specify a multi-character modifier
97       (e.g.  'ee*').
98
99       If called without an argument, or with an undef argument, all modifiers
100       explicitly asserted by this token are returned.
101
102   match_semantics
103        my $sem = $token->match_semantics();
104        defined $sem or $sem = 'undefined';
105        print "This token has $sem match semantics\n";
106
107       This method returns the match semantics asserted by the token, as one
108       of the strings 'a', 'aa', 'd', 'l', or 'u'. If no explicit match
109       semantics are asserted, this method returns "undef".
110
111   modifiers
112        my %mods = $token->modifiers();
113
114       Returns all modifiers asserted or negated by this token, and the values
115       set (true for asserted, false for negated). If called in scalar
116       context, returns a reference to a hash containing the values.
117
118   negates
119        $token->negates( 'i' ) and print "token negates i\n";
120        foreach ( $token->negates() ) { print "token negates $_\n" }
121
122       This method returns true if the token explicitly negates the given
123       modifier. The example would return true for the modifier in
124       "(?-i:foo)", but false for "(?i:foo)".
125
126       If called without an argument, or with an undef argument, all modifiers
127       explicitly negated by this token are returned.
128

SUPPORT

130       Support is by the author. Please file bug reports at
131       <https://rt.cpan.org>, or in electronic mail to the author.
132

AUTHOR

134       Thomas R. Wyant, III wyant at cpan dot org
135
137       Copyright (C) 2009-2020 by Thomas R. Wyant, III
138
139       This program is free software; you can redistribute it and/or modify it
140       under the same terms as Perl 5.10.0. For more details, see the full
141       text of the licenses in the directory LICENSES.
142
143       This program is distributed in the hope that it will be useful, but
144       without any warranty; without even the implied warranty of
145       merchantability or fitness for a particular purpose.
146
147
148
149perl v5.32.0                      2020-07-29  PPIx::Regexp::Token::Modifier(3)
Impressum