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 here-
20       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
24       second section that should be something like a separate token, but
25       isn't because a string can span from above the here-doc content to
26       below it.
27
28       So when parsing, this is what we do.
29
30       Firstly, the PPI::Token::HereDoc object, does not represent the "<<"
31       operator, or the "END_FLAG", or the content, or even the terminator.
32
33       It represents all of them at once.
34
35       The token itself has only the declaration part as its "content".
36
37         # This is what the content of a HereDoc token is
38         <<FOO
39
40         # Or this
41         <<"FOO"
42
43         # Or even this
44         <<      'FOO'
45
46       That is, the "operator", any whitespace separator, and the quoted or
47       bare terminator. So when you call the "content" method on a HereDoc
48       token, you get '<< "FOO"'.
49
50       As for the content and the terminator, when treated purely in "content"
51       terms they do not exist.
52
53       The content is made available with the "heredoc" method, and the name
54       of the terminator with the "terminator" method.
55
56       To make things work in the way you expect, PPI has to play some games
57       when doing line/column location calculation for tokens, and also during
58       the content parsing and generation processes.
59
60       Documents cannot simply by recreated by stitching together the token
61       contents, and involve a somewhat more expensive procedure, but the
62       extra expense should be relatively negligible unless you are doing huge
63       quantities of them.
64
65       Please note that due to the immature nature of PPI in general, we
66       expect "HereDocs" to be a rich (bad) source of corner-case bugs for
67       quite a while, but for the most part they should more or less DWYM.
68
69   Comparison to other string types
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       The "heredoc" method is the authoritative method for accessing the
84       contents of the "HereDoc" object.
85
86       It returns the contents of the here-doc as a list of newline-terminated
87       strings. If called in scalar context, it returns the number of lines in
88       the here-doc, excluding the terminator line.
89
90   terminator
91       The "terminator" method returns the name of the terminating string for
92       the here-doc.
93
94       Returns the terminating string as an unescaped string (in the rare case
95       the terminator has an escaped quote in it).
96

TO DO

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

SUPPORT

107       See the support section in the main module.
108

AUTHOR

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