view release on metacpan or search on metacpan
local/lib/perl5/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',
local/lib/perl5/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.
local/lib/perl5/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 {
local/lib/perl5/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;
}
local/lib/perl5/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
local/lib/perl5/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:
local/lib/perl5/Perl/Tidy/Formatter.pm view on Meta::CPAN
# Operators that the user can request break before or after.
# Note that some are keywords
@all_operators = qw(% + - * / x != == >= <= =~ !~ < > | &
= **= += *= &= <<= &&= -= /= |= >>= ||= //= .= %= ^= x=
. : ? && || and or err xor
);
# We can remove semicolons after blocks preceded by these keywords
@q =
qw(BEGIN END CHECK INIT AUTOLOAD DESTROY UNITCHECK continue if elsif else
unless while until for foreach given when default);
@is_block_without_semicolon{@q} = (1) x scalar(@q);
# We will allow semicolons to be added within these block types
# as well as sub and package blocks.
# NOTES:
# 1. Note that these keywords are omitted:
# switch case given when default sort map grep
# 2. It is also ok to add for sub and package blocks and a labeled block
# 3. But not okay for other perltidy types including:
# { } ; G t
# 4. Test files: blktype.t, blktype1.t, semicolon.t
@q =
qw( BEGIN END CHECK INIT AUTOLOAD DESTROY UNITCHECK continue if elsif else
unless do while until eval for foreach );
@ok_to_add_semicolon_for_block_type{@q} = (1) x scalar(@q);
# 'L' is token for opening { at hash key
@q = qw< L { ( [ >;
@is_opening_type{@q} = (1) x scalar(@q);
# 'R' is token for closing } at hash key
@q = qw< R } ) ] >;
@is_closing_type{@q} = (1) x scalar(@q);
local/lib/perl5/Perl/Tidy/Tokenizer.pm view on Meta::CPAN
# beginning of tokenizer hashes
#------------------------------
my %matching_start_token = ( '}' => '{', ']' => '[', ')' => '(' );
# These block types terminate statements and do not need a trailing
# semicolon
# patched for SWITCH/CASE/
my %is_zero_continuation_block_type;
my @q;
@q = qw( } { BEGIN END CHECK INIT AUTOLOAD DESTROY UNITCHECK continue ;
if elsif else unless while until for foreach switch case given when);
@is_zero_continuation_block_type{@q} = (1) x scalar(@q);
my %is_logical_container;
@q = qw(if elsif unless while and or err not && ! || for foreach);
@is_logical_container{@q} = (1) x scalar(@q);
my %is_binary_type;
@q = qw(|| &&);
@is_binary_type{@q} = (1) x scalar(@q);
local/lib/perl5/Perl/Tidy/Tokenizer.pm view on Meta::CPAN
## return $last_nonblank_token;
## }
# brace after label:
elsif ( $last_nonblank_type eq 'J' ) {
return $last_nonblank_token;
}
# otherwise, look at previous token. This must be a code block if
# it follows any of these:
# /^(BEGIN|END|CHECK|INIT|AUTOLOAD|DESTROY|UNITCHECK|continue|if|elsif|else|unless|do|while|until|eval|for|foreach|map|grep|sort)$/
elsif ($is_code_block_token{$last_nonblank_token}
|| $is_grep_alias{$last_nonblank_token} )
{
# Bug Patch: Note that the opening brace after the 'if' in the following
# snippet is an anonymous hash ref and not a code block!
# print 'hi' if { x => 1, }->{x};
# We can identify this situation because the last nonblank type
# will be a keyword (instead of a closing paren)
if (
local/lib/perl5/Perl/Tidy/Tokenizer.pm view on Meta::CPAN
# Note: 'field' will be added by sub check_options if --use-feature=class
@q = qw(my our state);
@is_my_our_state{@q} = (1) x scalar(@q);
# These tokens may precede a code block
# patched for SWITCH/CASE/CATCH. Actually these could be removed
# now and we could let the extended-syntax coding handle them.
# Added 'default' for Switch::Plain.
# Note: 'ADJUST' will be added by sub check_options if --use-feature=class
@q =
qw( BEGIN END CHECK INIT AUTOLOAD DESTROY UNITCHECK continue if elsif else
unless do while until eval for foreach map grep sort
switch case given when default catch try finally);
@is_code_block_token{@q} = (1) x scalar(@q);
# Note: this hash was formerly named '%is_not_zero_continuation_block_type'
# to contrast it with the block types in '%is_zero_continuation_block_type'
@q = qw( sort map grep eval do );
@is_sort_map_grep_eval_do{@q} = (1) x scalar(@q);
@q = qw( sort map grep );
local/lib/perl5/Perl/Tidy/Tokenizer.pm view on Meta::CPAN
CHECK
DESTROY
END
EQ
GE
GT
INIT
LE
LT
NE
UNITCHECK
abs
accept
alarm
and
atan2
bind
binmode
bless
break
caller