DateTime::Format::Builder::Parser - Online Linux Manual PageSection : 3
Updated : 2022-01-21
Source : perl v5.34.0
Note : User Contributed Perl Documentation

NAMEDateTime::Format::Builder::Parser − Parser creation

VERSIONversion 0.83

SYNOPSIS​ my $class = 'DateTime::Format::Builder::Parser'; ​ my $parser = $class−>create_single_parser(%specs);

DESCRIPTIONThis is a utility class for DateTime::Format::Builder that handles creation of parsers. It is to here that Builder delegates most of its responsibilities.

METHODSThere are two sorts of methods in this class. Those used by parser implementations and those used by Builder. It is generally unlikely the user will want to use any of them. They are presented, grouped according to use.

Parameter Handling (implementations)These methods allow implementations to have validation of their arguments in a standard manner and due to Parser's implementation, these methods also allow Parser to determine which implementation to use. Common parameters These parameters appear for all parser implementations. These are primarily documented in DateTime::Format::Builder. • on_match • on_fail • postprocess • preprocess • label • length length may be a number or an arrayref of numbers indicating the length of the input. This lets us optimize in the case of static length input. If supplying an arrayref of numbers, please keep the number of numbers to a minimum. params ​ my $params = $self−>params; ​ validate( @_, $params ); Returns declared parameters and common parameters in a hashref suitable for handing to Params::Validate's validate function. params_all ​ my $all_params = $self−>params_all; Returns a hash of all the valid options. Not recommended for general use. valid_params ​ _ _PACKAGE_ _−>valid_params(%params); Arguments are as per Params::Validate's validate function. This method is used to declare what your valid arguments are in a parser specification. whose_params ​ my $class = whose_params( $key ); Internal function which merely returns to which class a parameter is unique. If not unique, returns undef.

Organizing and Creating Parserscreate_single_parser This takes a single specification and returns a coderef that is a parser that suits that specification. This is the end of the line for all the parser creation methods. It delegates no further. If a coderef is specified, then that coderef is immediately returned (it is assumed to be appropriate). The single specification (if not a coderef) can be either a hashref or a hash. The keys and values must be as per the specification. It is here that any arrays of callbacks are unified. It is also here that any parser implementations are used. With the spec that's given, the keys are looked at and whichever module is the first to have a unique key in the spec is the one to whom the spec is given. Note: please declare a valid_params argument with an uppercase letter. For example, if you're writing ​DateTime::Format::Builder::Parser::Fnord, declare a parameter called ​Fnord. Similarly, DTFBP::Strptime should have Strptime and ​DTFBP::Regex should have Regex. These latter two don't for backwards compatibility reasons. The returned parser will return either a DateTime object or undef. merge_callbacks Produce either undef or a single coderef from either undef, an empty array, a single coderef or an array of coderefs

create_multiple_parsersGiven the options block (as made from create_parser) and a list of single parser specifications, this returns a coderef that returns either the resultant DateTime object or undef. It first sorts the specifications using sort_parsers and then creates the function based on what that returned.

sort_parsersThis takes the list of specifications and sorts them while turning the specifications into parsers. It returns two values: the first is a hashref containing all the length based parsers. The second is an array containing all the other parsers. If any of the specs are not code or hash references, then it will call ​croak. Code references are put directly into the 'other' array. Any hash references without length keys are run through create_single_parser and the resultant parser is placed in the 'other' array. Hash references with length keys are run through ​create_single_parser, but the resultant parser is used as the value in the length hashref with the length being the key. If two or more parsers have the same length specified then an error is thrown.

create_parsercreate_class is mostly a wrapper around create_parser that does loops and stuff and calls create_parser to create the actual parsers. create_parser takes the parser specifications (be they single specifications or multiple specifications) and returns an anonymous coderef that is suitable for use as a method. The coderef will call croak in the event of being unable to parse the single string it expects as input. The simplest input is that of a single specification, presented just as a plain hash, not a hashref. This is passed directly to create_single_parser with the return value from that being wrapped in a function that lets it ​croak on failure, with that wrapper being returned. If the first argument to create_parser is an arrayref, then that is taken to be an options block (as per the multiple parser specification documented earlier). Any further arguments should be either hashrefs or coderefs. If the first argument after the optional arrayref is not a hashref or coderef then that argument and all remaining arguments are passed off to create_single_parser directly. If the first argument is a hashref or coderef, then it and the remaining arguments are passed to create_multiple_parsers. The resultant coderef from calling either of the creation methods is then wrapped in a function that calls croak in event of failure or the ​DateTime object in event of success.

FINDING IMPLEMENTATIONSParser automatically loads any parser classes in @INC. To be loaded automatically, you must be a ​DateTime::Format::Builder::Parser::XXX module. To be invisible, and not loaded, start your class with a lower class letter. These are ignored.

WRITING A PARSER IMPLEMENTATION

Naming your parserCreate a module and name it in the form ​DateTime::Format::Builder::Parser::XXX where XXX is whatever you like, so long as it doesn't start with a lower case letter. Alternatively, call it something completely different if you don't mind the users explicitly loading your module. I'd recommend keeping within the DateTime::Format::Builder namespace though ​−−− at the time of writing I've not given thought to what non-auto loaded ones should be called. Any ideas, please email me.

Declaring specification argumentsCall <DateTime::Format::Builder::Parser−valid_params>> with ​Params::Validate style arguments. For example: ​ DateTime::Format::Builder::Parser−>valid_params( ​ params => { type => ARRAYREF }, ​ Regex => { ​ type => SCALARREF, ​ callbacks => { ​ 'is a regex' => sub { ref(shift) eq 'Regexp' }}}); Start one of the key names with a capital letter. Ideally that key should match the XXX from earlier. This will be used to help identify which module a parser specification should be given to. The key names on_match, on_fail, postprocess, preprocess, label and length are predefined. You are recommended to make use of them. You may ignore length as sort_parsers takes care of that.

Define create_parserA class method of the name create_parser that does the following: Its arguments are as for a normal method (i.e. class as first argument). The other arguments are the result from a call to Params::Validate according to your specification (the valid_params earlier), i.e. a hash of argument name and value. The return value should be a coderef that takes a date string as its first argument and returns either a DateTime object or undef.

CallbacksIt is preferred that you support some callbacks to your parsers. In particular, preprocess, on_match, on_fail and postprocess. See the main Builder docs for the appropriate placing of calls to the callbacks.

SEE ALSOdatetime@perl.org mailing list. http://datetime.perl.org/ perl, DateTime, DateTime::Format::Builder. Params::Validate. DateTime::Format::Builder::Parser::generic, DateTime::Format::Builder::Parser::Dispatch, DateTime::Format::Builder::Parser::Quick, DateTime::Format::Builder::Parser::Regex, DateTime::Format::Builder::Parser::Strptime.

SUPPORTBugs may be submitted at <https://github.com/houseabsolute/DateTime−Format−Builder/issues>. I am also usually active on IRC as 'autarch' on irc://irc.perl.org.

SOURCEThe source code repository for DateTime-Format-Builder can be found at <https://github.com/houseabsolute/DateTime−Format−Builder>.

AUTHORS• Dave Rolsky <autarch@urth.org> • Iain Truskett <spoon@cpan.org>

COPYRIGHT AND LICENSEThis software is Copyright (c) 2020 by Dave Rolsky. This is free software, licensed under: ​ The Artistic License 2.0 (GPL Compatible) The full text of the license can be found in the ​LICENSE file included with this distribution.
0
Johanes Gumabo
Data Size   :   32,319 byte
man-DateTime::Format::Builder::Parser.3pmBuild   :   2024-12-05, 20:55   :  
Visitor Screen   :   x
Visitor Counter ( page / site )   :   4 / 184,939
Visitor ID   :     :  
Visitor IP   :   18.191.171.10   :  
Visitor Provider   :   AMAZON-02   :  
Provider Position ( lat x lon )   :   39.962500 x -83.006100   :   x
Provider Accuracy Radius ( km )   :   1000   :  
Provider City   :   Columbus   :  
Provider Province   :   Ohio ,   :   ,
Provider Country   :   United States   :  
Provider Continent   :   North America   :  
Visitor Recorder   :   Version   :  
Visitor Recorder   :   Library   :  
Online Linux Manual Page   :   Version   :   Online Linux Manual Page - Fedora.40 - march=x86-64 - mtune=generic - 24.12.05
Online Linux Manual Page   :   Library   :   lib_c - 24.10.03 - march=x86-64 - mtune=generic - Fedora.40
Online Linux Manual Page   :   Library   :   lib_m - 24.10.03 - march=x86-64 - mtune=generic - Fedora.40
Data Base   :   Version   :   Online Linux Manual Page Database - 24.04.13 - march=x86-64 - mtune=generic - fedora-38
Data Base   :   Library   :   lib_c - 23.02.07 - march=x86-64 - mtune=generic - fedora.36

Very long time ago, I have the best tutor, Wenzel Svojanovsky . If someone knows the email address of Wenzel Svojanovsky , please send an email to johanes_gumabo@yahoo.co.id .
If error, please print screen and send to johanes_gumabo@yahoo.co.id
Under development. Support me via PayPal.

ERROR : Need New Coding :         (parse_manual_page_|249|DateTime::Format::Builder::Parser.3pm|36/37|el══─{─══.|.el══─{─══. ds -- \|\(em\| )         (htmlprn|149|DateTime::Format::Builder::Parser.3pm|36/37|.el══─{─══. ds --  —  |.el══─{─══. ds -- \|\(em\| )         (parse_manual_page_|249|DateTime::Format::Builder::Parser.3pm|43|br══─}─══|'br══─}─══ )         (htmlprn|149|DateTime::Format::Builder::Parser.3pm|43|'br══─}─══ |'br══─}─══ )