PPI-Tester

 view release on metacpan or  search on metacpan

lib/PPI/Tester.pm  view on Meta::CPAN

	}

	# Parse and dump the content
	my $Document = eval { PPI::Document->new( \$source ) };
	if ( ref $@ ) {
		# Dump the exception
		my $dumper = Devel::Dumpvar->new(
			to => 'return',
		) or die "Failed to create dumper";
		my $dumped =  $dumper->dump($@);

		# Chop off the initial "0  " from "0  PPI::Exception"
		$dumped =~ s/^...//;

		return $self->_error( $dumped );
	} elsif ( $@ ) {
		return $self->_error("Uncaught Error!\n  $@");
	} elsif ( ! $Document ) {
		return $self->_error("Failed to parse document");
	}

	# Does the user want to strip whitespace?
	if ( $self->{Option}->{StripWhitespace}->IsChecked ) {
		$Document->prune('PPI::Token::Whitespace');
	}

	# Dump the Document to the dump screen
	my $Dumper = PPI::Dumper->new( $Document, indent => 2 );
	unless ( $Dumper ) {
		return $self->_error("Failed to created PPI::Document dumper");
	}
	my $output = $Dumper->string;
	unless ( $output ) {
		return $self->_error("Dumper failed to generate output");
	}
	$self->{Output}->SetValue( $output );

	# Keep the focus on the code
	$self->{Code}->SetFocus;

	1;
}

sub _error {
	my $self    = shift;
	my $message = join "\n", @_;
	$self->{Output}->SetValue( $message );
	return 1;
}

1;

=pod

=head1 NAME

PPI::Tester - A wxPerl-based interactive PPI debugger/tester

=head1 DESCRIPTION

This package implements a wxWindows desktop application which provides the
ability to interactively test the PPI perl parser.

The C<PPI::Tester> module implements the application, but is itself of no
use to the user. The launcher for the application 'ppitester' is installed
with this module, and can be launched by simply typing the following from
the command line.

  ppitester

When launched, the application consists of two vertical panels. The left
panel is where you should type in your code sample. As the left hand panel
is changed, a PPI::Dumper output is continuously updated in the right
hand panel.

There is a toolbar at the top of the application with two icon buttons,
currently without icons. The first toolbar button clears the panels, the
second is a placeholder for loading in code from a file, and is not yet
implemented. ( It's early days yet for this application ).

=head1 TO DO

- There are no icons on the toolbar buttons

- An option is needed to save both the left and right panels into
  a matching pair of files, compatible with the lexer testing script.

=head1 SUPPORT

To file a bug against this module, in a way you can keep track of, see the CPAN
bug tracking system.

L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=PPI-Tester>

For general comments, contact the maintainer.

=head1 AUTHOR

Adam Kennedy E<lt>adamk@cpan.orgE<gt>

=head1 SEE ALSO

L<PPI::Manual>, L<http://sf.net/parseperl>

=head1 COPYRIGHT

Copyright 2004 - 2009 Adam Kennedy.

This program is free software; you can redistribute
it and/or modify it under the same terms as Perl itself.

The full text of the license can be found in the
LICENSE file included with this module.

=cut



( run in 1.881 second using v1.01-cache-2.11-cpan-39bf76dae61 )