1PPI::Lexer(3)         User Contributed Perl Documentation        PPI::Lexer(3)
2
3
4

NAME

6       PPI::Lexer - The PPI Lexer
7

SYNOPSIS

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

DESCRIPTION

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

METHODS

52       new
53
54       The "new" constructor creates a new "PPI::Lexer" object. The object
55       itself is merely used to hold various buffers and state data during the
56       lexing process, and holds no significant data between ->lex_xxxxx
57       calls.
58
59       Returns a new "PPI::Lexer" object
60
61       lex_file $filename
62
63       The "lex_file" method takes a filename as argument. It then loads the
64       file, creates a PPI::Tokenizer for the content and lexes the token
65       stream produced by the tokenizer. Basically, a sort of all-in-one
66       method for getting a PPI::Document object from a file name.
67
68       Returns a PPI::Document object, or "undef" on error.
69
70       lex_source $string
71
72       The "lex_source" method takes a normal scalar string as argument. It
73       creates a PPI::Tokenizer object for the string, and then lexes the
74       resulting token stream.
75
76       Returns a PPI::Document object, or "undef" on error.
77
78       lex_tokenizer $Tokenizer
79
80       The "lex_tokenizer" takes as argument a PPI::Tokenizer object. It lexes
81       the token stream from the tokenizer into a PPI::Document object.
82
83       Returns a PPI::Document object, or "undef" on error.
84
85       errstr
86
87       For any error that occurs, you can use the "errstr", as either a static
88       or object method, to access the error message.
89
90       If no error occurs for any particular action, "errstr" will return
91       false.
92

TO DO

94       - Add optional support for some of the more common source filters
95
96       - Some additional checks for blessing things into various Statement and
97       Structure subclasses.
98

SUPPORT

100       See the support section in the main module.
101

AUTHOR

103       Adam Kennedy <adamk@cpan.org>
104
106       Copyright 2001 - 2006 Adam Kennedy.
107
108       This program is free software; you can redistribute it and/or modify it
109       under the same terms as Perl itself.
110
111       The full text of the license can be found in the LICENSE file included
112       with this module.
113
114
115
116perl v5.8.8                       2006-09-23                     PPI::Lexer(3)
Impressum