PPI
view release on metacpan or search on metacpan
- Updated Module::Install to 0.87
- Added Test::NoWarnings to the test suite
- Added support for qw{foo} in addition to for ('foo')
- Added support for vstrings again
- Now supports the 5.10 "state" keyword.
(As far as PPI is concerned it's a synonym for "my")
- Now supports switch statements.
- Now supports the smart match operator (~~).
- Now supports keeping track of line numbers and file names as
affected by the #line directive.
- Now supports UNITCHECK blocks.
- Statement::Include::module_version() implemented.
- Statement::Include::arguments() implemented.
- Statement::Variable::symbols() implemented.
- Token::QuoteLike::Words::literal() implemented.
- Token::Quote::Double::simplify() fixed.
- Element line_number(), column_number(), visual_column_number(),
logical_line_number(), and logical_filename() implemented.
- Support for Unicode byte order marks (PPI::Token::BOM) added.
- Token::Word::method_call() implemented.
- Element::descendant_of() and Element::ancestor_of() implemented.
lib/PPI/Lexer.pm view on Meta::CPAN
#####################################################################
# Lex Methods - Statement Object
# Keyword -> Statement Subclass
my %STATEMENT_CLASSES = (
# Things that affect the timing of execution
'BEGIN' => 'PPI::Statement::Scheduled',
'CHECK' => 'PPI::Statement::Scheduled',
'UNITCHECK' => 'PPI::Statement::Scheduled',
'INIT' => 'PPI::Statement::Scheduled',
'END' => 'PPI::Statement::Scheduled',
# Special subroutines for which 'sub' is optional
'AUTOLOAD' => 'PPI::Statement::Sub',
'DESTROY' => 'PPI::Statement::Sub',
# Loading and context statement
'package' => 'PPI::Statement::Package',
# 'use' => 'PPI::Statement::Include',
lib/PPI/Statement.pm view on Meta::CPAN
=head1 STATEMENT CLASSES
Please note that unless documented themselves, these classes are yet to be
frozen/finalised. Names may change slightly or be added or removed.
=head2 L<PPI::Statement::Scheduled>
This covers all "scheduled" blocks, chunks of code that are executed separately
from the main body of the code, at a particular time. This includes all
C<BEGIN>, C<CHECK>, C<UNITCHECK>, C<INIT> and C<END> blocks.
=head2 L<PPI::Statement::Package>
A package declaration, as defined in L<perlfunc|perlfunc/package>.
=head2 L<PPI::Statement::Include>
A statement that loads or unloads another module.
This includes 'use', 'no', and 'require' statements.
lib/PPI/Statement/Scheduled.pm view on Meta::CPAN
BEGIN {
# Executes as soon as this block is fully defined
...
}
CHECK {
# Executes after overall compile-phase in reverse order
...
}
UNITCHECK {
# Executes after compile-phase of individual module in reverse order
...
}
INIT {
# Executes just before run-time
...
}
END {
lib/PPI/Statement/Scheduled.pm view on Meta::CPAN
and
$child->complete
);
}
=pod
=head2 type
The C<type> method returns the type of scheduled block, which should always be
one of C<'BEGIN'>, C<'CHECK'>, C<'UNITCHECK'>, C<'INIT'> or C<'END'>.
=cut
sub type {
my $self = shift;
my @children = $self->schildren or return undef;
$children[0]->content eq 'sub'
? $children[1]->content
: $children[0]->content;
}
lib/PPI/Statement/Sub.pm view on Meta::CPAN
=head1 INHERITANCE
PPI::Statement::Sub
isa PPI::Statement
isa PPI::Node
isa PPI::Element
=head1 DESCRIPTION
Except for the special BEGIN, CHECK, UNITCHECK, INIT, and END subroutines
(which are part of L<PPI::Statement::Scheduled>) all subroutine declarations
are lexed as a PPI::Statement::Sub object.
Primarily, this means all of the various C<sub foo {}> statements, but also
forward declarations such as C<sub foo;> or C<sub foo($);>. It B<does not>
include anonymous subroutines, as these are merely part of a normal statement.
=head1 METHODS
C<PPI::Statement::Sub> has a number of methods in addition to the standard
lib/PPI/Statement/Sub.pm view on Meta::CPAN
=pod
=head2 reserved
The C<reserved> method provides a convenience method for checking to see
if this is a special reserved subroutine. It does not check against any
particular list of reserved sub names, but just returns true if the name
is all uppercase, as defined in L<perlsub>.
Note that in the case of BEGIN, CHECK, UNITCHECK, INIT and END, these will be
defined as L<PPI::Statement::Scheduled> objects, not subroutines.
Returns true if it is a special reserved subroutine, or false if not.
=cut
sub reserved {
my $self = shift;
my $name = $self->name or return '';
# perlsub is silent on whether reserveds can contain:
t/ppi_statement_scheduled.t view on Meta::CPAN
use lib 't/lib';
use PPI::Test::pragmas;
use Test::More tests => 280 + ($ENV{AUTHOR_TESTING} ? 1 : 0);
use PPI ();
use Helper 'safe_new';
SUB_WORD_OPTIONAL: {
for my $name ( qw( BEGIN CHECK UNITCHECK INIT END ) ) {
for my $sub ( '', 'sub ' ) {
# '{}' -- function definition
# ';' -- function declaration
# '' -- function declaration with missing semicolon
for my $followed_by ( ' {}', '{}', ';', '' ) {
test_sub_as( $sub, $name, $followed_by );
}
}
}
t/ppi_statement_sub.t view on Meta::CPAN
is( $sub_statement->block, $block, "$code: block matches" );
is( !$sub_statement->block, !!$sub_statement->forward, "$code: block and forward are opposites" );
}
}
RESERVED: {
for my $test (
{ code => 'sub BEGIN {}', reserved => 1 },
{ code => 'sub CHECK {}', reserved => 1 },
{ code => 'sub UNITCHECK {}', reserved => 1 },
{ code => 'sub INIT {}', reserved => 1 },
{ code => 'sub END {}', reserved => 1 },
{ code => 'sub AUTOLOAD {}', reserved => 1 },
{ code => 'sub CLONE_SKIP {}', reserved => 1 },
{ code => 'sub __SUB__ {}', reserved => 1 },
{ code => 'sub _FOO {}', reserved => 1 },
{ code => 'sub FOO9 {}', reserved => 1 },
{ code => 'sub FO9O {}', reserved => 1 },
{ code => 'sub FOo {}', reserved => 0 },
) {
( run in 1.111 second using v1.01-cache-2.11-cpan-748bfb374f4 )