Query: data::phrasebook::loader::text
OS: debian
Section: 3pm
Format: Original Unix Latex Style Formatted with HTML and a Horizontal Scroll Bar
Data::Phrasebook::Loader::Text(3pm) User Contributed Perl Documentation Data::Phrasebook::Loader::Text(3pm)NAMEData::Phrasebook::Loader::Text - Absract your phrases with plain text files.SYNOPSISuse Data::Phrasebook; my $q = Data::Phrasebook->new( class => 'Fnerk', loader => 'Text', file => 'phrases.txt', ); # use default delimiters (:variable) my $phrase = $q->fetch($keyword,{variable => 'substitute'}); # use Template Toolkit style delimiters $q->delimiters( qr{ [% s* (w+) s* %] }x ); my $phrase = $q->fetch($keyword,{variable => 'substitute'});DESCRIPTIONThis loader plugin implements phrasebook patterns using plain text files. Phrases can be contained within one or more dictionaries, with each phrase accessible via a unique key. Phrases may contain placeholders, please see Data::Phrasebook for an explanation of how to use these. Groups of phrases are kept in a dictionary. In this implementation a single file is one complete dictionary. An example plain text file: foo=Welcome to :my world. It is a nice :place. Within the phrase text placeholders can be used, which are then replaced with the appropriate values once the get() method is called. The default style of placeholders can be altered using the delimiters() method.INHERITANCEData::Phrasebook::Loader::Text inherits from the base class Data::Phrasebook::Loader::Base. See that module for other available methods and documentation.METHODSload Given a "file", load it. "file" must contain a valid phrase map. my $file = 'english.txt'; $loader->load( $file ); This method is used internally by Data::Phrasebook::Generic's "data" method, to initialise the data store. To utilise the dictionary framework for a Plain Text phrasebook, the idea is to use a directory of files, where the directory is passed via the "file" argument and the dictionary, the specific name of the file, is passed via the "dictionary" argument. my $file = '/tmp/phrasebooks'; my $dictionary = 'english.txt'; $loader->load( $file, $dictionary ); get Returns the phrase stored in the phrasebook, for a given keyword. my $value = $loader->get( $key ); dicts Having instantiated the "Data::Phrasebook" object class, and using the "file" attribute as a directory path, the object can return a list of the current dictionaries available as: my $pb = Data::Phrasebook->new( loader => 'Text', file => '/tmp/phrasebooks', ); my @dicts = $pb->dicts; or my @dicts = $pb->dicts( $path ); keywords Having instantiated the "Data::Phrasebook" object class, using the "file" and "dict" attributes as required, the object can return a list of the current keywords available as: my $pb = Data::Phrasebook->new( loader => 'Text', file => '/tmp/phrasebooks', dict => 'TEST', ); my @keywords = $pb->keywords; or my @keywords = $pb->keywords( $path, $dict ); Note that $path can either be the directory path, where $dict must be the specific file name of the dictionary, or the full path of the dictionary file. In the second instance, the function will not load a dictionary, but can be used to interrogate the contents of a known dictionary.SEE ALSOData::Phrasebook.SUPPORTPlease see the README file.AUTHORBarbie, <barbie@cpan.org> for Miss Barbell Productions <http://www.missbarbell.co.uk>.COPYRIGHT AND LICENSECopyright (C) 2004-2010 Barbie for Miss Barbell Productions. This module is free software; you can redistribute it and/or modify it under the Artistic Licence v2. perl v5.10.1 2010-08-31 Data::Phrasebook::Loader::Text(3pm)
Similar Topics in the Unix Linux Community |
---|
Get data from delimited file |
Run perl script on files in multiple directories |
Changing Text with sed or awk |
Data extraction in perl variable |
Generating Dynamic Scripts |