1Template::Plugin::DatafUisleer(3C)ontributed Perl DocumeTnetmaptliaotne::Plugin::Datafile(3)
2
3
4
6 Template::Plugin::Datafile - Plugin to construct records from a simple
7 data file
8
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
18 This plugin provides a simple facility to construct a list of hash
19 references, 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").
26 An optional "delim" parameter may also be provided to specify an
27 alternate 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
34 whitespace. Subsequent lines then defines records containing data
35 items, also delimited by colons. e.g.
36
37 id : name : email : tel
38 abw : Andy Wardley : abw@tt2.org : 555-1234
39 sam : Simon Matthews : sam@tt2.org : 555-9876
40
41 Each line is read, split into composite fields, and then used to
42 initialise a hash array containing the field names as relevant keys.
43 The plugin returns a blessed list reference containing the hash
44 references 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
55 Should handle file names relative to "INCLUDE_PATH". Doesn't permit
56 use of '":"' in a field. Some escaping mechanism is required.
57
59 Andy Wardley <abw@wardley.org> <http://wardley.org/>
60
62 Copyright (C) 1996-2007 Andy Wardley. All Rights Reserved.
63
64 This module is free software; you can redistribute it and/or modify it
65 under the same terms as Perl itself.
66
68 Template::Plugin
69
70
71
72perl v5.28.0 2014-04-23 Template::Plugin::Datafile(3)