1Template::Plugin::DatafUisleer(3C)ontributed Perl DocumeTnetmaptliaotne::Plugin::Datafile(3)
2
3
4

NAME

6       Template::Plugin::Datafile - Plugin to construct records from a simple
7       data file
8

SYNOPSIS

10           [% USE mydata = datafile('/path/to/datafile') %]
11           [% USE mydata = datafile('/path/to/datafile', delim = '⎪') %]
12
13           [% FOREACH record = mydata %]
14              [% record.this %]  [% record.that %]
15           [% END %]
16

DESCRIPTION

18       This plugin provides a simple facility to construct a list of hash ref‐
19       erences, each of which represents a data record of known structure,
20       from a data file.
21
22           [% USE datafile(filename) %]
23
24       A absolute filename must be specified (for this initial implementation
25       at least - in a future version it might also use the INCLUDE_PATH).  An
26       optional 'delim' parameter may also be provided to specify an alternate
27       delimiter character.
28
29           [% USE userlist = datafile('/path/to/file/users')     %]
30           [% USE things   = datafile('items', delim = '⎪') %]
31
32       The format of the file is intentionally simple.  The first line defines
33       the field names, delimited by colons with optional surrounding white‐
34       space.  Subsequent lines then defines records containing data items,
35       also delimited by colons.  e.g.
36
37           id : name : email : tel
38           abw : Andy Wardley : abw@cre.canon.co.uk : 555-1234
39           neilb : Neil Bowers : neilb@cre.canon.co.uk : 555-9876
40
41       Each line is read, split into composite fields, and then used to ini‐
42       tialise a hash array containing the field names as relevant keys.  The
43       plugin returns a blessed list reference containing the hash references
44       in the order as defined in the file.
45
46           [% FOREACH user = userlist %]
47              [% user.id %]: [% user.name %]
48           [% END %]
49
50       The first line of the file must contain the field definitions.  After
51       the first line, blank lines will be ignored, along with comment line
52       which start with a '#'.
53

BUGS

55       Should handle file names relative to INCLUDE_PATH.  Doesn't permit use
56       of ':' in a field.  Some escaping mechanism is required.
57

AUTHOR

59       Andy Wardley <abw@wardley.org>
60
61       <http://wardley.org/http://wardley.org/>
62

VERSION

64       2.72, distributed as part of the Template Toolkit version 2.18,
65       released on 09 February 2007.
66
68         Copyright (C) 1996-2007 Andy Wardley.  All Rights Reserved.
69
70       This module is free software; you can redistribute it and/or modify it
71       under the same terms as Perl itself.
72

SEE ALSO

74       Template::Plugin
75
76
77
78perl v5.8.8                       2007-02-09     Template::Plugin::Datafile(3)
Impressum