#!/usr/bin/perl -w

=pod

=head1 NAME

pler - The DWIM Perl Debugger

=head1 DESCRIPTION

B<pler> is a small script which provides a sanity layer for debugging
test scripts in Perl distributions.

While L<prove> has is highly useful program for manually running one or
more groups of scripts in a distribution, what we also need is something
that works similarly in a debugging context.

This script checks that the environment is sound, runs some cleanup tasks
if needed, makes sure you are in the right directory, and then hands off
to the perl debugger as normal.

=cut

use 5.005;
use strict;
use File::Spec::Functions ':ALL';
use ADAMK::Debug;

use vars qw{$VERSION};
BEGIN {
	$VERSION = '0.07';
}





#####################################################################
# Main Script

my $perl   = $^X;
my $script = shift @ARGV;
unless ( defined $script ) {
	error "Did not provide a test script name";
}
unless ( -f $script ) {
	error "Test script '$script' does not exist";
}

# Rerun make if needed
if ( in_distroot and has_makefile ) {
	run('make');
}

# Build the command to execute
my @flags = ();
if ( has_blib ) {
	push @flags, '-Mblib';
} elsif ( has_lib ) {
	push @flags, '-Ilib';
}

# Hand off to the perl debugger
handoff( join ' ', $perl, @flags, '-d', $script );

=pod

=head1 TO DO

- Allow execution from the base or F<t> directory.

- Automatically rerun F<make>.

- Automatically run the F<Makefile.PL>

=head1 SUPPORT

All bugs should be filed via the bug tracker at

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

For other issues, or commercial enhancement and support, contact the author

=head1 AUTHOR

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

=head1 SEE ALSO

L<prove>, L<http://ali.as/>

=head1 COPYRIGHT

Copyright 2006 Adam Kennedy. All rights reserved.

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
