1PPI::Lexer(3) User Contributed Perl Documentation PPI::Lexer(3)
2
3
4
6 PPI::Lexer - The PPI Lexer
7
9 use PPI;
10
11 # Create a new Lexer
12 my $Lexer = PPI::Lexer->new;
13
14 # Build a PPI::Document object from a Token stream
15 my $Tokenizer = PPI::Tokenizer->load('My/Module.pm');
16 my $Document = $Lexer->lex_tokenizer($Tokenizer);
17
18 # Build a PPI::Document object for some raw source
19 my $source = "print 'Hello World!'; kill(Humans->all);";
20 $Document = $Lexer->lex_source($source);
21
22 # Build a PPI::Document object for a particular file name
23 $Document = $Lexer->lex_file('My/Module.pm');
24
26 The is the PPI Lexer. In the larger scheme of things, its job is to
27 take token streams, in a variety of forms, and "lex" them into nested
28 structures.
29
30 Pretty much everything in this module happens behind the scenes at this
31 point. In fact, at the moment you don't really need to instantiate the
32 lexer at all, the three main methods will auto-instantiate themselves a
33 "PPI::Lexer" object as needed.
34
35 All methods do a one-shot "lex this and give me a PPI::Document
36 object".
37
38 In fact, if you are reading this, what you probably want to do is to
39 just "load a document", in which case you can do this in a much more
40 direct and concise manner with one of the following.
41
42 use PPI;
43
44 $Document = PPI::Document->load( $filename );
45 $Document = PPI::Document->new( $string );
46
47 See PPI::Document for more details.
48
49 For more unusual tasks, by all means forge onwards.
50
52 new
53 The "new" constructor creates a new "PPI::Lexer" object. The object
54 itself is merely used to hold various buffers and state data during the
55 lexing process, and holds no significant data between ->lex_xxxxx
56 calls.
57
58 Returns a new "PPI::Lexer" object
59
60 lex_file $filename
61 The "lex_file" method takes a filename as argument. It then loads the
62 file, creates a PPI::Tokenizer for the content and lexes the token
63 stream produced by the tokenizer. Basically, a sort of all-in-one
64 method for getting a PPI::Document object from a file name.
65
66 Returns a PPI::Document object, or "undef" on error.
67
68 lex_source $string
69 The "lex_source" method takes a normal scalar string as argument. It
70 creates a PPI::Tokenizer object for the string, and then lexes the
71 resulting token stream.
72
73 Returns a PPI::Document object, or "undef" on error.
74
75 lex_tokenizer $Tokenizer
76 The "lex_tokenizer" takes as argument a PPI::Tokenizer object. It lexes
77 the token stream from the tokenizer into a PPI::Document object.
78
79 Returns a PPI::Document object, or "undef" on error.
80
81 errstr
82 For any error that occurs, you can use the "errstr", as either a static
83 or object method, to access the error message.
84
85 If no error occurs for any particular action, "errstr" will return
86 false.
87
89 - Add optional support for some of the more common source filters
90
91 - Some additional checks for blessing things into various Statement and
92 Structure subclasses.
93
95 See the support section in the main module.
96
98 Adam Kennedy <adamk@cpan.org>
99
101 Copyright 2001 - 2011 Adam Kennedy.
102
103 This program is free software; you can redistribute it and/or modify it
104 under the same terms as Perl itself.
105
106 The full text of the license can be found in the LICENSE file included
107 with this module.
108
109
110
111perl v5.30.1 2020-01-30 PPI::Lexer(3)