]> git.vpit.fr Git - perl/modules/Test-Valgrind.git/blob - lib/Test/Valgrind/Command/PerlScript.pm
This is 1.01
[perl/modules/Test-Valgrind.git] / lib / Test / Valgrind / Command / PerlScript.pm
1 package Test::Valgrind::Command::PerlScript;
2
3 use strict;
4 use warnings;
5
6 =head1 NAME
7
8 Test::Valgrind::Command::PerlScript - A Test::Valgrind command that invokes a perl script.
9
10 =head1 VERSION
11
12 Version 1.01
13
14 =cut
15
16 our $VERSION = '1.01';
17
18 =head1 DESCRIPTION
19
20 This command is meant to abstract the argument list handling of a C<perl> script.
21
22 =cut
23
24 use base qw/Test::Valgrind::Command::Perl Test::Valgrind::Carp/;
25
26 =head1 METHODS
27
28 This class inherits L<Test::Valgrind::Command::Perl>.
29
30 =head2 C<< new file => $file, [ taint_mode => $taint_mode ], ... >>
31
32 Your usual constructor.
33
34 C<$file> is the path to the C<perl> script you want to run.
35
36 C<$taint_mode> is a boolean that specifies if the script should be run under taint mode.
37 If C<undef> is passed (which is the default), the constructor will try to infer it from the shebang line of the script.
38
39 Other arguments are passed straight to C<< Test::Valgrind::Command::Perl->new >>.
40
41 =cut
42
43 sub new {
44  my $class = shift;
45  $class = ref($class) || $class;
46
47  my %args = @_;
48
49  my $file       = delete $args{file};
50  $class->_croak('Invalid script file') unless $file and -e $file;
51  my $taint_mode = delete $args{taint_mode};
52
53  my $self = bless $class->SUPER::new(%args), $class;
54
55  $self->{file} = $file;
56
57  if (not defined $taint_mode and open my $fh, '<', $file) {
58   my $first = <$fh>;
59   close $fh;
60   if ($first and my ($args) = $first =~ /^\s*#\s*!\s*perl\s*(.*)/) {
61    $taint_mode = 1 if $args =~ /(?:^|\s)-T(?:$|\s)/;
62   }
63   $taint_mode = 0 unless defined $taint_mode;
64  }
65  $self->{taint_mode} = $taint_mode;
66
67  return $self;
68 }
69
70 sub new_trainer { Test::Valgrind::Command::Perl->new_trainer }
71
72 =head2 C<file>
73
74 Read-only accessor for the C<file> option.
75
76 =head2 C<taint_mode>
77
78 Read-only accessor for the C<taint_mode> option.
79
80 =cut
81
82 eval "sub $_ { \$_[0]->{$_} }" for qw/file taint_mode/;
83
84 sub args {
85  my $self = shift;
86
87  return $self->SUPER::args(@_),
88         (('-T') x!! $self->taint_mode),
89         $self->file
90 }
91
92 =head1 SEE ALSO
93
94 L<Test::Valgrind>, L<Test::Valgrind::Command::Perl>.
95
96 =head1 AUTHOR
97
98 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
99
100 You can contact me by mail or on C<irc.perl.org> (vincent).
101
102 =head1 BUGS
103
104 Please report any bugs or feature requests to C<bug-test-valgrind at rt.cpan.org>, or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Valgrind>.
105 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
106
107 =head1 SUPPORT
108
109 You can find documentation for this module with the perldoc command.
110
111     perldoc Test::Valgrind::Command::PerlScript
112
113 =head1 COPYRIGHT & LICENSE
114
115 Copyright 2009 Vincent Pit, all rights reserved.
116
117 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
118
119 =cut
120
121 1; # End of Test::Valgrind::Command::PerlScript