NAME Locale::TextDomain::OO::Extract::Base::RegexBasedExtractor - Extract data using regexes
$Id: RegexBasedExtractor.pm 683 2017-08-22 18:41:42Z steffenw $
$HeadURL: svn+ssh://steffenw@svn.code.sf.net/p/perl-gettext-oo/code/extract/trunk/lib/Locale/TextDomain/OO/Extract/Base/RegexBasedExtractor.pm $
VERSION
2.007
DESCRIPTION
This module extracts data using regexes to store anywhere.
SYNOPSIS
use Path::Tiny qw(path);
use Locale::TextDomain::OO::Extract::Base::RegexBasedExtractor;
my $extractor = Locale::TextDomain::OO::Extract::Base::RegexBasedExtractor->new(
content_ref => \'... string to extract ...',
start_rule => qr{ ... }xms,
rules => [ qr{ ... ( ... ) ... }xms ],
debug_code => sub { ... },
);
$extractor->extract;
SUBROUTINES/METHODS
method new
All parameters are optional.
my $extractor = Locale::TextDomain::OO::Extract::Base::RegexBasedExtractor->new(
# how to find such lines
start_rule => qr{ __ n?p?x? \( }xms,
# how to find the parameters
rules => [
[
# __( 'text'
# __x( 'text'
qr{ __ (x?) \s* \( \s* }xms,
qr{ \s* }xms,
# You can re-use the next reference.
# It is a subdefinition.
[
qr{
[']
(
[^\\']* # normal text
(?: \\ . [^\\']* )* # maybe followed by escaped char and normal text
)
[']
}xms,
],
],
# The next array reference describes an alternative
# and not a subdefinition.
'or',
[
# next alternative e.g.
# __n( 'context' , 'text'
# __nx( 'context' , 'text'
...
],
],
# debug output for other rules than perl
debug_code => sub {
my ($group, $message) = @_;
# group can anything, used groups are:
# - stack start
# - rules start
# - rules last
# - rules parent
# - rules child
# - rules try
# - rules current pos
# - rules match
# - rules no match
# - stack clean
},
);
method extract
Run the extractor
$extractor->extract;
method content_ref
Set/get the content to extract by scalar reference to that string.
method start_rule
Set/get the rule as regex reference that is matching the begin of expected string.
method rules
Set/get an array reference owith all the rules to extract.
method debug_code, clear_debug_code
Set/get a code reference if debugging is needed.
To switch off run method clear_debug_code.
method stack
Set/get the stack as array reference during extraction
EXAMPLE
Inside of this distribution is a directory named example. Run this *.pl files.
DIAGNOSTICS
none
CONFIGURATION AND ENVIRONMENT
none
DEPENDENCIES
INCOMPATIBILITIES
not known
BUGS AND LIMITATIONS
none
SEE ALSO
AUTHOR
Steffen Winkler
LICENSE AND COPYRIGHT
Copyright (c) 2009 - 2017, Steffen Winkler <steffenw at cpan.org>
. All rights reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.