View on
יובל קוג'מן (Yuval Kogman) > Locale-Maketext-Lexicon-Slurp-0.01 > Locale::Maketext::Lexicon::Slurp



Annotate this POD

View/Report Bugs
Module Version: 0.01   Source  


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.

Used by 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.

If unspecified then all of the files in dir are used.

Used by get_files.


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.

Used by get_files.


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.

Used by get_files.


The binmode to apply after opening a file for reading.

Used by 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.

Used by get_files.

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.

parse (@args)

Called by Locale::Maketext::Lexicon. Used internally to set up the lexicon entries.

read_file (%args)

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".

Additional, and currently unused arguments passed to this method are:


The ID of the message


The arguments given to maketext for interpolation.

get_files ($args)

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.

readdir ($dir)

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.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

syntax highlighting: