.\" Automatically generated by Pod::Man 4.11 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Encode::Mapper 3pm" .TH Encode::Mapper 3pm "2020-11-10" "perl v5.30.3" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Encode::Mapper \- Rewrite rules compiler and interpreter .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Encode::Mapper; ############################################# Enjoy the ride ^^ \& \& use Encode::Mapper \*(Aq:others\*(Aq, \*(Aq:silent\*(Aq; # syntactic sugar for compiler options .. \& \& Encode::Mapper\->options ( # .. equivalent, see more in the text \& \*(Aqothers\*(Aq => sub { shift }, \& \*(Aqsilent\*(Aq => 1, \& ); \& \& Encode::Mapper\->options ( # .. resetting, but not to use \*(Aquse\*(Aq !!! \& \*(Aqothers\*(Aq => undef, \& \*(Aqsilent\*(Aq => 0 \& ); \& \& ## Types of rules for mapping the data and controlling the engine\*(Aqs configuration ##### \& \& @rules = ( \& \*(Aqx\*(Aq, \*(Aqy\*(Aq, # single \*(Aqx\*(Aq be \*(Aqy\*(Aq, unless greediness prefers .. \& \*(Aqxx\*(Aq, \*(AqY\*(Aq, # .. double \*(Aqx\*(Aq be \*(AqY\*(Aq or other rules \& \& \*(Aquc(x)x\*(Aq, sub { \*(Aqsorry ;)\*(Aq }, # if \*(Aqx\*(Aq follows \*(Aquc(x)\*(Aq, be sorry, else .. \& \& \*(Aquc(x)\*(Aq, [ \*(Aq\*(Aq, \*(AqX\*(Aq ], # .. alias this *engine\-initial* string \& \*(Aqxuc(x)\*(Aq, [ \*(Aq\*(Aq, \*(AqxX\*(Aq ], # likewise, alias for the \*(Aqx\*(Aq prefix \& \& \*(AqXxx\*(Aq, [ sub { $i++; \*(Aq\*(Aq }, \*(AqX\*(Aq ], # count the still married \*(Aqx\*(Aq \& ); \& \& ## Constructors of the engine, i.e. one Encode::Mapper instance ####################### \& \& $mapper = Encode::Mapper\->compile( @rules ); # engine constructor \& $mapper = Encode::Mapper\->new( @rules ); # equivalent alias \& \& ## Elementary performance of the engine ############################################### \& \& @source = ( \*(Aqx\*(Aq, \*(Aqxx\*(Aq, \*(Aqxxuc(x)\*(Aq, \*(Aqxxx\*(Aq, \*(Aq\*(Aq, \*(Aqxx\*(Aq ); # distribution of the data .. \& $source = join \*(Aq\*(Aq, @source; # .. is ignored in this sense \& \& @result = ($mapper\->process(@source), $mapper\->recover()); # the mapping procedure \& @result = ($mapper\->process($source), $mapper\->recover()); # completely equivalent \& \& $result = join \*(Aq\*(Aq, map { ref $_ eq \*(AqCODE\*(Aq ? $_\->() : $_ } @result; \& \& # maps \*(Aqxxxxxuc(x)xxxxx\*(Aq into ( \*(AqY\*(Aq, \*(AqY\*(Aq, \*(Aq\*(Aq, \*(Aqy\*(Aq, CODE(...), CODE(...), \*(Aqy\*(Aq ), .. \& # .. then converts it into \*(AqYYyy\*(Aq, setting $i == 2 \& \& @follow = $mapper\->compute(@source); # follow the engine\*(Aqs computation over @source \& $dumper = $mapper\->dumper(); # returns the engine as a Data::Dumper object \& \& ## Module\*(Aqs higher API implemented for convenience #################################### \& \& $encoder = [ $mapper, Encode::Mapper\->compile( ... ), ... ]; # reference to mappers \& $result = Encode::Mapper\->encode($source, $encoder, \*(Aqutf8\*(Aq); # encode down to \*(Aqutf8\*(Aq \& \& $decoder = [ $mapper, Encode::Mapper\->compile( ... ), ... ]; # reference to mappers \& $result = Encode::Mapper\->decode($source, $decoder, \*(Aqutf8\*(Aq); # decode up from \*(Aqutf8\*(Aq .Ve .SH "ABSTRACT" .IX Header "ABSTRACT" .Vb 4 \& Encode::Mapper serves for intuitive, yet efficient construction of mappings for Encode. \& The module finds direct application in Encode::Arabic. It provides an object\-oriented \& programming interface to convert data consistently, follow the engine\*(Aqs computation, \& dump the engine using Data::Dumper, etc. .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" It looks like the author of the extension ... ;) preferred giving formal and terse examples to writing English. Please, see Encode::Arabic where Encode::Mapper is used for solving complex real-world problems. .SS "\s-1INTRO AND RULE TYPES\s0" .IX Subsection "INTRO AND RULE TYPES" The module's core is an algorithm which, from the rules given by the user, builds a finite-state transducer, i.e. an engine performing greedy search in the input stream and producing output data and side effects relevant to the results of the search. Transducers may be linked one with another, thus forming multi-level devices suitable for nontrivial encoding/decoding tasks. .PP The rules declare which input sequences of bytes to search for, and what to do upon their occurrence. If the left-hand side (\s-1LHS\s0) of a rule is the longest left-most string out of those applicable on the input, the righ-hand side (\s-1RHS\s0) of the rule is evaluated. The \s-1RHS\s0 defines the corresponding output string, and possibly controls the engine as if the extra text were prepended before the rest of the input: .PP .Vb 3 \& $A => $X # $A .. literal string \& # $X .. literal string or subroutine reference \& $A => [$X, $Y] # $Y .. literal string for which \*(Aqlength $Y < length $A\*(Aq .Ve .PP The order of the rules does not matter, except when several rules with the same \s-1LHS\s0 are stated. In such a case, redefinition warning is usually issued before overriding the \s-1RHS.\s0 .SS "LOW-LEVEL \s-1METHODS\s0" .IX Subsection "LOW-LEVEL METHODS" .ie n .IP "compile (\fI\f(CI$class\fI,\fR @rules)" 4 .el .IP "compile (\fI\f(CI$class\fI,\fR \f(CW@rules\fR)" 4 .IX Item "compile ($class, @rules)" .PD 0 .ie n .IP "compile (\fI\f(CI$class\fI,\fR $opts, @rules)" 4 .el .IP "compile (\fI\f(CI$class\fI,\fR \f(CW$opts\fR, \f(CW@rules\fR)" 4 .IX Item "compile ($class, $opts, @rules)" .PD The constructor of an Encode::Mapper instance. The first argument is the name of the class, the rest is the list of rules ... \s-1LHS\s0 odd elements, \s-1RHS\s0 even elements, unless the first element is a reference to an array or a hash, which then becomes \f(CW$opts\fR. .Sp If \f(CW$opts\fR is recognized, it is used to modify the compiler \f(CW\*(C`options\*(C'\fR locally for the engine being constructed. If an option is not overridden, its global setting holds. .Sp The compilation algorithm, and the search algorithm itself, were inspired by Aho-Corasick and Boyer-Moore algorithms, and by the studies of finite automata with the restart operation. The engine is implemented in the classical sense, using hashes for the transition function for instance. We expect to improve this to Perl code evaluation, if the speed-up is significant. .Sp It is to explore the way Perl's regular expressions would cope with the task, i.e. verify our initial doubts which prevented us from trying. Since Encode::Mapper's functionality is much richer than pure search, simulating it completely might be resource-expensive and non-elegant. Therefore, experiment reports are welcome. .ie n .IP "new (\fI\f(CI$class\fI,\fR @list)" 4 .el .IP "new (\fI\f(CI$class\fI,\fR \f(CW@list\fR)" 4 .IX Item "new ($class, @list)" Name alias to the \f(CW\*(C`compile\*(C'\fR constructor. .ie n .IP "process (\fI\f(CI$obj\fI,\fR @list)" 4 .el .IP "process (\fI\f(CI$obj\fI,\fR \f(CW@list\fR)" 4 .IX Item "process ($obj, @list)" Process the input list with the engine. There is no resetting within the call of the method. Internally, the text in the list is \f(CW\*(C`split\*(C'\fR into bytes, and there is just no need for the user to \f(CW\*(C`join\*(C'\fR his/hers strings or lines of data. Note the unveiled properties of the Encode::Mapper class as well: .Sp .Vb 3 \& sub process ($@) { # returns the list of search results performed by Mapper \& my $obj = shift @_; \& my (@returns, $phrase, $token, $q); \& \& use bytes; # ensures splitting into one\-byte tokens \& \& $q = $obj\->{\*(Aqcurrent\*(Aq}; \& \& foreach $phrase (@_) { \& foreach $token (split //, $phrase) { \& until (defined $obj\->{\*(Aqtree\*(Aq}[$q]\->{$token}) { \& push @returns, @{$obj\->{\*(Aqbell\*(Aq}[$q]}; \& $q = $obj\->{\*(Aqskip\*(Aq}[$q]; \& } \& $q = $obj\->{\*(Aqtree\*(Aq}[$q]\->{$token}; \& } \& } \& \& $obj\->{\*(Aqcurrent\*(Aq} = $q; \& \& return @returns; \& } .Ve .ie n .IP "recover (\fI\f(CI$obj\fI,\fR $r, $q)" 4 .el .IP "recover (\fI\f(CI$obj\fI,\fR \f(CW$r\fR, \f(CW$q\fR)" 4 .IX Item "recover ($obj, $r, $q)" Since the search algorithm is greedy and the engine does not know when the end of the data comes, there must be a method to tell. Normally, \f(CW\*(C`recover\*(C'\fR is called on the object without the other two optional parameters setting the initial and the final state, respectively. .Sp .Vb 3 \& sub recover ($;$$) { # returns the \*(Aqin\-progress\*(Aq search result and resets Mapper \& my ($obj, $r, $q) = @_; \& my (@returns); \& \& $q = $obj\->{\*(Aqcurrent\*(Aq} unless defined $q; \& \& until ($q == 0) { \& push @returns, @{$obj\->{\*(Aqbell\*(Aq}[$q]}; \& $q = $obj\->{\*(Aqskip\*(Aq}[$q]; \& } \& \& $obj\->{\*(Aqcurrent\*(Aq} = defined $r ? $r : 0; \& \& return @returns; \& } .Ve .ie n .IP "compute (\fI\f(CI$obj\fI,\fR @list)" 4 .el .IP "compute (\fI\f(CI$obj\fI,\fR \f(CW@list\fR)" 4 .IX Item "compute ($obj, @list)" Tracks down the computation over the list of data, resetting the engine before and after to its initial state. Developers might like this ;) .Sp .Vb 1 \& local $\e = "\en"; local $, = ":\et"; # just define the display \& \& foreach $result ($mapper\->compute($source)) { # follow the computation \& \& print "Token" , $result\->[0]; \& print "Source" , $result\->[1]; \& print "Output" , join " + ", @{$result\->[2]}; \& print "Target" , $result\->[3]; \& print "Bell" , join ", ", @{$result\->[4]}; \& print "Skip" , $result\->[5]; \& } .Ve .ie n .IP "dumper (\fI\f(CI$obj\fI,\fR $ref)" 4 .el .IP "dumper (\fI\f(CI$obj\fI,\fR \f(CW$ref\fR)" 4 .IX Item "dumper ($obj, $ref)" The individual instances of Encode::Mapper can be stored as revertible data structures. For minimalistic reasons, dumping needs to include explicit short-identifier references to the empty array and the empty hash of the engine. For details, see Data::Dumper. .Sp .Vb 2 \& sub dumper ($;$) { \& my ($obj, $ref) = @_; \& \& $ref = [\*(AqL\*(Aq, \*(AqH\*(Aq, \*(Aqmapper\*(Aq] unless defined $ref; \& \& require Data::Dumper; \& \& return Data::Dumper\->new([$obj\->{\*(Aqnull\*(Aq}{\*(Aqlist\*(Aq}, $obj\->{\*(Aqnull\*(Aq}{\*(Aqhash\*(Aq}, $obj], $ref); \& } .Ve .ie n .IP "describe (\fI\f(CI$obj\fI,\fR $ref)" 4 .el .IP "describe (\fI\f(CI$obj\fI,\fR \f(CW$ref\fR)" 4 .IX Item "describe ($obj, $ref)" Describes the Encode::Mapper object and returns a hash of the characteristics. If \f(CW$ref\fR is defined, the information is also \f(CW\*(C`print\*(C'\fRed into the \f(CW$ref\fRerenced stream, or to \&\f(CW\*(C`STDERR\*(C'\fR if \f(CW$ref\fR is not a filehandle. .SS "HIGH-LEVEL \s-1METHODS\s0" .IX Subsection "HIGH-LEVEL METHODS" In the Encode world, one can work with different encodings and is also provided a function for telling if the data are in Perl's internal utf8 format or not. In the Encode::Mapper business, one is encouraged to compile different mappers and stack them on top of each other, getting an easy-to-work-with filtering device. .PP In combination, this module offers the following \f(CW\*(C`encode\*(C'\fR and \f(CW\*(C`decode\*(C'\fR methods. In their prototypes, \&\f(CW$encoder\fR/\f(CW$decoder\fR represent merely a reference to an array of mappers, although mathematics might do more than that in future implementations ;) .PP Currently, the mappers involved are not reset with \f(CW\*(C`recover\*(C'\fR before the computation. See the \f(CW\*(C`\-\-join\*(C'\fR option for more comments on the code: .PP .Vb 7 \& foreach $mapper (@{$_[2]}) { # either $encoder or $decoder \& $join = defined $mapper\->{\*(Aqjoin\*(Aq} ? $mapper\->{\*(Aqjoin\*(Aq} : \& defined $option{\*(Aqjoin\*(Aq} ? $option{\*(Aqjoin\*(Aq} : ""; \& $text = join $join, map { \& UNIVERSAL::isa($_, \*(AqCODE\*(Aq) ? $_\->() : $_ \& } $mapper\->process($text), $mapper\->recover(); \& } .Ve .ie n .IP "encode (\fI\f(CI$class\fI,\fR $text, $encoder, $enc)" 4 .el .IP "encode (\fI\f(CI$class\fI,\fR \f(CW$text\fR, \f(CW$encoder\fR, \f(CW$enc\fR)" 4 .IX Item "encode ($class, $text, $encoder, $enc)" If \f(CW$enc\fR is defined, the \f(CW$text\fR is encoded into that encoding, using Encode. Then, the \&\f(CW$encoder\fR's engines are applied in series on the data. The returned text should have the utf8 flag off. .ie n .IP "decode (\fI\f(CI$class\fI,\fR $text, $decoder, $enc)" 4 .el .IP "decode (\fI\f(CI$class\fI,\fR \f(CW$text\fR, \f(CW$decoder\fR, \f(CW$enc\fR)" 4 .IX Item "decode ($class, $text, $decoder, $enc)" The \f(CW$text\fR is run through the sequence of engines in \f(CW$decoder\fR. If the result does not have the utf8 flag on, decoding from \f(CW$enc\fR is further performed by Encode. If \f(CW$enc\fR is not defined, utf8 is assumed. .SS "\s-1OPTIONS AND EXPORT\s0" .IX Subsection "OPTIONS AND EXPORT" The language the Encode::Mapper engine works on is not given exclusively by the rules passed as parameters to the \f(CW\*(C`compile\*(C'\fR or \f(CW\*(C`new\*(C'\fR constructor methods. The nature of the compilation is influenced by the current setting of the following options: .IP "\-\-complement" 4 .IX Item "--complement" This option accepts a reference to an array declaring rules which are to complement the rules of the constructor. Redefinition warnings are issued only if you redefine within the option's list, not when a rule happens to be overridden during compilation. .IP "\-\-override" 4 .IX Item "--override" Overrides the rules of the constructor. Redefinition warnings are issued, though. You might, for example, want to preserve all \s-1XML\s0 markup in the data you are going to process through your encoders/decoders: .Sp .Vb 1 \& \*(Aqoverride\*(Aq => [ # override rules of these LHS .. there\*(Aqs no other tricks ^^ \& \& ( # combinations of \*(Aq<\*(Aq and \*(Aq>\*(Aq with the other bytes \& map { \& \& my $x = chr $_; \& \& "<" . $x, [ "<" . $x, ">" ], # propagate the \*(Aq>\*(Aq sign implying .. \& ">" . $x, [ $x, ">" ], # .. preservation of the bytes \& \& } 0x00..0x3B, 0x3D, 0x3F..0xFF \& ), \& \& ">>", ">", # stop the whole process .. \& "<>", "<>", # .. do not even start it \& \& "><", [ "<", ">" ], # rather than nested \*(Aq<\*(Aq and \*(Aq>\*(Aq, .. \& "<<", [ "<<", ">" ], \& \& ">\e\e<", [ "<", ">" ], # .. prefer these escape sequences \& ">\e\e\e\e", [ "\e\e", ">" ], \& ">\e\e>", [ ">", ">" ], \& \& ">", ">", # singular symbols may migrate right .. \& "<", "<", # .. or preserve the rest of the data \& ] .Ve .IP "\-\-others" 4 .IX Item "--others" If defined, this option controls how to deal with 'others', i.e. bytes of input for which there is no rule, by defining rules for them. In case this option gets a code reference, the referenced subroutine will be called with the 'other' \s-1LHS\s0 parameter to get the rule's \s-1RHS.\s0 Otherwise, a defined scalar value will become the \s-1RHS\s0 of each 'other' \s-1LHS.\s0 .Sp To preserve the 'other' bytes, you can use .Sp .Vb 1 \& \*(Aqothers\*(Aq => sub { shift } # preserve every non\-treated byte .Ve .Sp the effect of which is similar to including the \f(CW\*(C`map\*(C'\fR to the \f(CW\*(C`\-\-complement\*(C'\fR rules: .Sp .Vb 1 \& \*(Aqcomplement\*(Aq => [ ( map { ( chr $_ ) x 2 } 0x00..0xFF ), ... ] # ... is your rules .Ve .Sp You may of course wish to return undefined values if there are any non-treated bytes in the input. In order for the \f(CW\*(C`undef\*(C'\fR to be a correct \s-1RHS,\s0 you have to protect it once more by the \f(CW\*(C`sub\*(C'\fR like this: .Sp .Vb 1 \& \*(Aqothers\*(Aq => sub { sub { undef } } .Ve .IP "\-\-silent" 4 .IX Item "--silent" Setting it to a true value will prevent any warnings issued during the engine's compilation, mostly reflecting an incorrect or dubious use of a rule. .IP "\-\-join" 4 .IX Item "--join" This option enables less memory-requiring representation of the engines. If this option is defined when the constructor is called, the setting is stored in the instance internally. Any lists of literal \s-1RHS\s0 which are to be emitted simultaneously from the engine are joined into a string with the option's value, empty lists turn into empty strings. If an engine was compiled with this option defined, the value will be used to join output of \f(CW\*(C`encode\*(C'\fR and \f(CW\*(C`decode\*(C'\fR, too. If not, either the current value of the option or the empty string will help instead. .PP The keywords of options can be in mixed case and/or start with any number of dashes, and the next element in the list is taken as the option's value. There are special keywords, however, beginning with a colon and not gulping down the next element: .IP ":others" 4 .IX Item ":others" Equivalent to the code \f(CW\*(C`\*(Aqothers\*(Aq => sub { shift }\*(C'\fR explained above. .IP ":silent" 4 .IX Item ":silent" Equivalent to \f(CW\*(C`\*(Aqsilent\*(Aq => 1\*(C'\fR, or rather to the maximum silence if more degrees of it are introduced in the future. .IP ":join" 4 .IX Item ":join" Equivalent to \f(CW\*(Aqjoin\*(Aq => \*(Aq\*(Aq\fR. Use this option if you are going to dump and load the new engine often, and if you do not miss the list-supporting uniformity of \f(CW\*(C`process\*(C'\fR and \f(CW\*(C`recover\*(C'\fR. .PP Compiler options are associated with package names in the \f(CW%Encode::Mapper::options\fR variable, and confined to them. While \f(CW\*(C`options\*(C'\fR and \f(CW\*(C`import\*(C'\fR perform the setting with respect to the caller package, accessing the hash directly is neither recommended, nor restricted. .PP There is a nice compile-time invocation of \f(CW\*(C`import\*(C'\fR with the \f(CW\*(C`use\*(C'\fR\f(CW\*(C` Encode::Mapper LIST\*(C'\fR idiom, which you might prefer to explicit method calls. Local modification of the package's global setting that applies just to the engine being constructed is done by supplying the options as an extra parameter to \f(CW\*(C`compile\*(C'\fR. .PP .Vb 1 \& use Data::Dump \*(Aqdump\*(Aq; # pretty data printing is below \& \& $Encode::Mapper::options{\*(AqByForce\*(Aq} = { qw \*(Aq:others \- silent errors\*(Aq }; \& \& package ByMethod; # import called at compile time \& # no warnings, \*(Aqsilent\*(Aq is true \& Encode::Mapper\->options(\*(Aqcomplement\*(Aq => [ \*(AqX\*(Aq, \*(AqY\*(Aq ], \*(Aqothers\*(Aq => \*(AqX\*(Aq); \& use Encode::Mapper \*(Aqsilent\*(Aq => 299_792_458; \& \& package main; # import called at compile time \& # \*(Aqnon\-existent\*(Aq may exist once \& print dump %Encode::Mapper::options; \& use Encode::Mapper \*(Aq:others\*(Aq, \*(Aq:silent\*(Aq, \*(Aqnon\-existent\*(Aq, \*(Aqone\*(Aq; \& \& # ( \& # "ByMethod", \& # { complement => ["X", "Y"], others => "X", silent => 299_792_458 }, \& # "ByForce", \& # { ":others" => "\-", silent => "errors" }, \& # "main", \& # { "non\-existent" => "one", others => sub { "???" }, silent => 1 }, \& # ) .Ve .ie n .IP "options (\fI\f(CI$class\fI,\fR @list)" 4 .el .IP "options (\fI\f(CI$class\fI,\fR \f(CW@list\fR)" 4 .IX Item "options ($class, @list)" If \f(CW$class\fR is defined, enforces the options in the list globally for the calling package. The return value of this method is the state of the options before the proposed changes were set. If \f(CW$class\fR is undefined, nothing is set, only the canonized forms of the declared keywords and their values are returned. .ie n .IP "import (\fI\f(CI$class\fI,\fR @list)" 4 .el .IP "import (\fI\f(CI$class\fI,\fR \f(CW@list\fR)" 4 .IX Item "import ($class, @list)" This module does not export any symbols. This method just calls \f(CW\*(C`options\*(C'\fR, provided there are some elements in the list. .SH "SEE ALSO" .IX Header "SEE ALSO" There are related theoretical studies which the implementation may have touched. You might be interested in Aho-Corasick and Boyer-Moore algorithms as well as in finite automata with the restart operation. .PP Encode, Encode::Arabic, Data::Dumper .PP Encode Arabic: Exercise in Functional Parsing .SH "AUTHOR" .IX Header "AUTHOR" Otakar Smrz \f(CW\*(C`\*(C'\fR, .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" Copyright (C) 2003\-2014 Otakar Smrz .PP This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.