Devel-DumpTrace

 view release on metacpan or  search on metacpan

lib/Devel/DumpTrace/PPI.pm  view on Meta::CPAN

package Devel::DumpTrace::PPI;
use Devel::DumpTrace;
use Devel::DumpTrace::Const;
use PadWalker;
use Scalar::Util;
use Data::Dumper;
use Carp;
use strict;
use warnings;

local $| = 1;

croak "Devel::DumpTrace::PPI may not be used ",
      "when \$Devel::DumpTrace::NO_PPI ",
      "is set (Did you load 'Devel::DumpTrace::noPPI'?\n"
    if $Devel::DumpTrace::NO_PPI;
eval {use PPI;
      1}
  or croak "PPI not installed. Can't use Devel::DumpTrace::PPI module";


# functions in this file that override functions in Devel/DumpTrace.pm

*Devel::DumpTrace::get_source = *get_source_PPI;
*Devel::DumpTrace::evaluate_and_display_line = *evaluate_and_display_line_PPI;
*Devel::DumpTrace::handle_deferred_output = *handle_deferred_output_PPI;

*_display_style = *Devel::DumpTrace::_display_style;
*evaluate = *Devel::DumpTrace::evaluate;
*current_position_string = *Devel::DumpTrace::current_position_string;
*dumptrace = *Devel::DumpTrace::dumptrace;

$Devel::DumpTrace::PPI::VERSION = '0.28';
use constant ADD_IMPLICIT_ => 1;
use constant DECORATE_FOR => 1;
use constant DECORATE_FOREACH => 1;
use constant DECORATE_WHILE => 1;
use constant DECORATE_ELSIF => 1;

# built-in functions that may use $_ implicitly
# make %implicit_ a package, not lexical, variable on the off
# chance that anyone wants to customize this list
my %implicit_ = map {; $_ => 1 } qw(abs alarm chomp chop chr chroot cos
        defined eval exp glob hex int lc lcfirst length log lstat mkdir
        oct ord pos print quotemeta readlink readpipe ref require
        reverse rmdir sin split sqrt stat study uc ucfirst unlink
        unpack say);

# see  &preval
my %assign_ops_ = map {; $_ => 1 } qw(= += -= *= /= %= &= |= ^= .= x= **= &&=
                                       ||= //= <<= >>= ++ --);

# for persisting the PPI documents we create
my (%ppi_src, %ppi_doc);

my $last_file_sub_displayed = '';
my $last_file_line_displayed = '';
my %IGNORE_FILE_LINE = ();

sub import {
    foreach my $PPI_package (grep { m{^PPI[/.]} } keys %INC) {
	$PPI_package =~ s/\.pm$//;
	$PPI_package =~ s{/}{::}g;
	$Devel::DumpTrace::EXCLUDE_PKG{$PPI_package} = 1;

lib/Devel/DumpTrace/PPI.pm  view on Meta::CPAN

  $ perl -d:DumpTrace::PPI iffy.pl
  >>>   iffy.pl:14:[__top__]:
  >>>>> iffy.pl:1:[__top__]:  for ($a:-1=-1; $a:-1<=3; $a:-1++) {
  >>>   iffy.pl:2:[__top__]:  if ($a:-1 == 1) {
  >>>>> iffy.pl:9:[__top__]:  ELSEIF ($a:-1 == 1)
                                          ELSEIF ($a:-1 == 2)
                                          ELSEIF ($a:-1 == 3)
                                          ELSEIF ($a:-1 < 0)
                                          $b:5 = 5;
  >>>   iffy.pl:10:[__top__]: $b:5++;
  >>>   iffy.pl:2:[__top__]:  FOR-UPDATE: {$a:0++ } FOR-COND: {$a:0<=3; }
                                          if ($a:0 == 1) {
  >>>>> iffy.pl:12:[__top__]: ELSEIF ($a:0 == 1)
                                          ELSEIF ($a:0 == 2)
                                          ELSEIF ($a:0 == 3)
                                          ELSEIF ($a:0 < 0)
                                          ELSE
                                          $b:20 = 20;
  >>>   iffy.pl:2:[__top__]:  FOR-UPDATE: {$a:1++ } FOR-COND: {$a:1<=3; }
                                          if ($a:1 == 1) {
  >>>>> iffy.pl:3:[__top__]:  $b:1 = 1;
  >>>   iffy.pl:2:[__top__]:  FOR-UPDATE: {$a:2++ } FOR-COND: {$a:2<=3; }
                                          if ($a:2 == 1) {
  >>>>> iffy.pl:5:[__top__]:  ELSEIF ($a:2 == 1)
                                          ELSEIF ($a:2 == 2)
                                          $b:4 = 4;
  >>>   iffy.pl:2:[__top__]:  FOR-UPDATE: {$a:3++ } FOR-COND: {$a:3<=3; }
                                          if ($a:3 == 1) {
  >>>>> iffy.pl:7:[__top__]:  ELSEIF ($a:3 == 1)
                                          ELSEIF ($a:3 == 2)
                                          ELSEIF ($a:3 == 3)
                                          $b:9 = 9;

In this example, the C<ELSEIF> (I<expression>) and C<ELSE> decorators
indicate what expressions must have been evaluated to reach
the particular block of the statement that is to be executed.

=head1 SUBROUTINES/METHODS

None to worry about.

=head1 EXPORT

Nothing is or can be exported from this module.

=head1 DIAGNOSTICS

All output from this module is for diagnostics.

=head1 CONFIGURATION AND ENVIRONMENT

This module reads and respects the same environment variables 
as C<Devel::DumpTrace>. See 
L<Devel::DumpTrace|Devel::DumpTrace/"CONFIGURATION AND ENVIRONMENT"> 
for more information.

=head1 DEPENDENCIES

L<PPI|PPI> for understanding the structure of your Perl script.

L<PadWalker|PadWalker> for arbitrary access to lexical variables.

L<Scalar::Util|Scalar::Util> for the reference identification
convenience methods.

L<Text::Shorten|Text::Shorten> (bundled with this distribution)
for abbreviating long output, when desired.

=head1 INCOMPATIBILITIES

None known.

=head1 BUGS AND LIMITATIONS

See "BUGS AND LIMITATIONS" section in 
L<Devel::DumpTrace|Devel::DumpTrace/"BUGS AND LIMITATION">
for description of some known issues in both the PPI parser
and the basic parser.

See L<Devel::DumpTrace/"SUPPORT"> for other support information.
Report issues for this module with the C<Devel-DumpTrace> distribution.

=head1 AUTHOR

Marty O'Brien, E<lt>mob at cpan.orgE<gt>

=head1 LICENSE AND COPYRIGHT

Copyright 2010-2019 Marty O'Brien.

This program is free software; you can redistribute it and/or modify it
under the terms of either: the GNU General Public License as published
by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.

=cut



( run in 0.659 second using v1.01-cache-2.11-cpan-5735350b133 )