]> git.vpit.fr Git - perl/modules/Test-Valgrind.git/blob - lib/Test/Valgrind/Command/PerlScript.pm
This is 1.10
[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.10
13
14 =cut
15
16 our $VERSION = '1.10';
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 The package constructor, which takes several options :
33
34 =over 4
35
36 =item *
37
38 C<$file> is the path to the C<perl> script you want to run.
39
40 This option is mandatory.
41
42 =item *
43
44 C<$taint_mode> is actually handled by the parent class L<Test::Valgrind::Command::Perl>, but it gets special handling in this subclass : if C<undef> is passed (which is the default), the constructor will try to infer its right value from the shebang line of the script.
45
46 =back
47
48 Other arguments are passed straight to C<< Test::Valgrind::Command::Perl->new >>.
49
50 =cut
51
52 sub new {
53  my $class = shift;
54  $class = ref($class) || $class;
55
56  my %args = @_;
57
58  my $file = delete $args{file};
59  $class->_croak('Invalid script file') unless $file and -e $file;
60
61  my $taint_mode = delete $args{taint_mode};
62  if (not defined $taint_mode and open my $fh, '<', $file) {
63   my $first = <$fh>;
64   close $fh;
65   if ($first and my ($args) = $first =~ /^\s*#\s*!\s*perl\s*(.*)/) {
66    $taint_mode = 1 if $args =~ /(?:^|\s)-T(?:$|\s)/;
67   }
68   $taint_mode = 0 unless defined $taint_mode;
69  }
70
71  my $self = bless $class->SUPER::new(
72   taint_mode => $taint_mode,
73   %args,
74  ), $class;
75
76  $self->{file} = $file;
77
78  return $self;
79 }
80
81 sub new_trainer { Test::Valgrind::Command::Perl->new_trainer }
82
83 =head2 C<file>
84
85 Read-only accessor for the C<file> option.
86
87 =cut
88
89 sub file { $_[0]->{file} }
90
91 sub args {
92  my $self = shift;
93
94  return $self->SUPER::args(@_),
95         $self->file
96 }
97
98 =head1 SEE ALSO
99
100 L<Test::Valgrind>, L<Test::Valgrind::Command::Perl>.
101
102 =head1 AUTHOR
103
104 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
105
106 You can contact me by mail or on C<irc.perl.org> (vincent).
107
108 =head1 BUGS
109
110 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>.
111 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
112
113 =head1 SUPPORT
114
115 You can find documentation for this module with the perldoc command.
116
117     perldoc Test::Valgrind::Command::PerlScript
118
119 =head1 COPYRIGHT & LICENSE
120
121 Copyright 2009 Vincent Pit, all rights reserved.
122
123 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
124
125 =cut
126
127 1; # End of Test::Valgrind::Command::PerlScript