1PPI::Token::HereDoc(3)User Contributed Perl DocumentationPPI::Token::HereDoc(3)
2
3
4

NAME

6       PPI::Token::HereDoc - Token class for the here-doc
7

INHERITANCE

9         PPI::Token::HereDoc
10         isa PPI::Token
11             isa PPI::Element
12

DESCRIPTION

14       Here-docs are incredibly handy when writing Perl, but incredibly tricky
15       when parsing it, primarily because they don't follow the general flow
16       of input.
17
18       They jump ahead and nab lines directly off the input buffer. Whitespace
19       and newlines may not matter in most Perl code, but they matter in
20       here-docs.
21
22       They are also tricky to store as an object. They look sort of like an
23       operator and a string, but they don't act like it. And they have a sec‐
24       ond section that should be something like a separate token, but isn't
25       because a strong can span from above the here-doc content to below it.
26
27       So when parsing, this is what we do.
28
29       Firstly, the PPI::Token::HereDoc object, does not represent the "<<"
30       operator, or the "END_FLAG", or the content, or even the terminator.
31
32       It represents all of them at once.
33
34       The token itself has only the declaration part as its "content".
35
36         # This is what the content of a HereDoc token is
37         <<FOO
38
39         # Or this
40         <<"FOO"
41
42         # Or even this
43         <<      'FOO'
44
45       That is, the "operator", any whitespace separator, and the quoted or
46       bare terminator. So when you call the "content" method on a HereDoc
47       token, you get '<< "FOO"'.
48
49       As for the content and the terminator, when treated purely in "content"
50       terms they do not exist.
51
52       The content is made available with the "heredoc" method, and the name
53       of the terminator with the "terminator" method.
54
55       To make things work in the way you expect, PPI has to play some games
56       when doing line/column location calculation for tokens, and also during
57       the content parsing and generation processes.
58
59       Documents cannot simply by recreated by stitching together the token
60       contents, and involve a somewhat more expensive procedure, but the
61       extra expense should be relatively negligible unless you are doing huge
62       quantities of them.
63
64       Please note that due to the immature nature of PPI in general, we
65       expect "HereDocs" to be a rich (bad) source of corner-case bugs for
66       quite a while, but for the most part they should more or less DWYM.
67
68       Comparison to other string types
69
70       Although technically it can be considered a quote, for the time being
71       "HereDocs" are being treated as a completely separate "Token" subclass,
72       and will not be found in a search for PPI::Token::Quote or
73       "PPI::Token::QuoteLike objects".
74
75       This may change in the future, with it most likely to end up under
76       QuoteLike.
77

METHODS

79       Although it has the standard set of "Token" methods, "HereDoc" objects
80       have a relatively large number of unique methods all of their own.
81
82       heredoc
83
84       The "heredoc" method is the authoritative method for accessing the con‐
85       tents of the "HereDoc" object.
86
87       It returns the contents of the here-doc as a list of newline-terminated
88       strings. If called in scalar context, it returns the number of lines in
89       the here-doc, excluding the terminator line.
90
91       terminator
92
93       The "terminator" method returns the name of the terminating string for
94       the here-doc.
95
96       Returns the terminating string as an unescaped string (in the rare case
97       the terminator has an escaped quote in it).
98

TO DO

100       - Implement PPI::Token::Quote interface compatibility
101
102       - Check CPAN for any use of the null here-doc or here-doc-in-s///e
103
104       - Add support for the null here-doc
105
106       - Add support for here-doc in s///e
107

SUPPORT

109       See the support section in the main module.
110

AUTHOR

112       Adam Kennedy <adamk@cpan.org>
113
115       Copyright 2001 - 2006 Adam Kennedy.
116
117       This program is free software; you can redistribute it and/or modify it
118       under the same terms as Perl itself.
119
120       The full text of the license can be found in the LICENSE file included
121       with this module.
122
123
124
125perl v5.8.8                       2006-09-23            PPI::Token::HereDoc(3)
Impressum