Locale::Maketext::Lexicon::Slurp - One message per file Maketext lexicon.
use Locale::Maketext::Lexicon { en => [ Slurp => [ "/my/dir/en", regex => qr{\.html$} ] ], de => [ Slurp => [ "/my/dir/de", files => [qw/blah.html foo.html/] ], };
This maketext lexicon module provides a file based lexicon format, with the file name (or relative path) acting as the message id, and the file contents being the message string.
This is useful for displaying large bits of text, like several paragraphs of instructions, or the answers to an FAQ, without needing to bother with formatting and escaping the text in some format.
This lexicon provider is also geared towards subclassing. Hooks are provided to make subclassing easy, so that you may add interpolation using a template module, for example. See the "METHODS" section for more details.
The accepted options are:
The base directory for the message files
If the directory does not exist it's treated like a glob pattern. See files for more details.
files
Used by get_files.
get_files
An array reference or a glob pattern of files to use as messages.
If dir is also specified then the files are considered relative and the relative paths are the IDs. If dir is not specified, then the files are assumed to be valid full paths (relative or absolute) and the file name becomes the ID.
dir
If unspecified then all of the files in dir are used.
An regex filter to apply to file names. Gets matched on the full path.
This is always applied if it exists, even if filter also exists, and if globbing was used.
filter
An optional code ref filter to apply to files. Gets the lexicon factory object as the invocant, and a Path::Class::File object as the argument.
This is always applied if it exists, even if regex also exists, and if globbing was used.
regex
The binmode to apply after opening a file for reading.
binmode
Used by read_file.
read_file
A code reference (or method name) to use instead of readdir, for when something like recursion is needed and a subclass of this module is too daunting. See readdir (the method) for details.
readdir
If the argument list is odd sized, the first item is assumed to be the value of the dir argument.
These methods are not generally exposed to the user, but are documented for subclassing.
Called by Locale::Maketext::Lexicon. Used internally to set up the lexicon entries.
This base implementation of read_file reads the contents of the file specified by the path argument. Also takes an optional binmode argument, which can be set in the import statement. See "OPTIONS".
path
Additional, and currently unused arguments passed to this method are:
The ID of the message
The arguments given to maketext for interpolation.
maketext
Enumerate all the files (returns a hash reference of ID to path) in the specified source.
See "OPTIONS" for the parameters it supports and how they behave.
Used to list the sub items of a directory. Mostly a convenience method.
All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT.
Consider caching options (the the OS page cache should be enough).
Yuval Kogman
Copyright 2007 by Infinity Interactive, Inc.
http://www.iinteractive.com
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Locale::Maketext::Lexicon::Slurp, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Locale::Maketext::Lexicon::Slurp
CPAN shell
perl -MCPAN -e shell install Locale::Maketext::Lexicon::Slurp
For more information on module installation, please visit the detailed CPAN module installation guide.