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 [% USE mydata = datafile('/path/to/datafile', encoding = 'UTF-8') %]
13
14 [% FOREACH record = mydata %]
15 [% record.this %] [% record.that %]
16 [% END %]
17
19 This plugin provides a simple facility to construct a list of hash
20 references, each of which represents a data record of known structure,
21 from a data file.
22
23 [% USE datafile(filename) %]
24
25 A absolute filename must be specified (for this initial implementation
26 at least - in a future version it might also use the "INCLUDE_PATH").
27 An optional "delim" parameter may also be provided to specify an
28 alternate delimiter character. The optional "encoding" parameter may
29 be used to specify the input file encoding.
30
31 [% USE userlist = datafile('/path/to/file/users') %]
32 [% USE things = datafile('items', delim = '|') %]
33
34 The format of the file is intentionally simple. The first line defines
35 the field names, delimited by colons with optional surrounding
36 whitespace. Subsequent lines then defines records containing data
37 items, also delimited by colons. e.g.
38
39 id : name : email : tel
40 abw : Andy Wardley : abw@tt2.org : 555-1234
41 sam : Simon Matthews : sam@tt2.org : 555-9876
42
43 Each line is read, split into composite fields, and then used to
44 initialise a hash array containing the field names as relevant keys.
45 The plugin returns a blessed list reference containing the hash
46 references in the order as defined in the file.
47
48 [% FOREACH user = userlist %]
49 [% user.id %]: [% user.name %]
50 [% END %]
51
52 The first line of the file must contain the field definitions. After
53 the first line, blank lines will be ignored, along with comment line
54 which start with a '"#"'.
55
57 Should handle file names relative to "INCLUDE_PATH". Doesn't permit
58 use of '":"' in a field. Some escaping mechanism is required.
59
61 Andy Wardley <abw@wardley.org> <http://wardley.org/>
62
64 Copyright (C) 1996-2007 Andy Wardley. All Rights Reserved.
65
66 This module is free software; you can redistribute it and/or modify it
67 under the same terms as Perl itself.
68
70 Template::Plugin
71
72
73
74perl v5.32.0 2020-07-28 Template::Plugin::Datafile(3)