ARGV-OrDATA
view release on metacpan or search on metacpan
Revision history for ARGV-OrDATA
0.005 2024-11-27
New subroutines: is_using_data and is_using_argv.
0.004 2019-01-05
Use IO::Pty if available instead of skipping tests.
0.003 2018-12-28
Skip tests when stdin is not a terminal.
0.002 2018-12-28
Fix tests on MSWin and with non-standard Perl executable path.
0.001 2017-06-09
First version, released on an unsuspecting world.
You'll see this if you don't redirect something to the script's
STDIN or you don't specify a filename on the command line.
INSTALLATION
To install this module, run the following commands:
perl Makefile.PL
make
make test
make install
SUPPORT AND DOCUMENTATION
After installing, you can find documentation for this module with the
perldoc command.
perldoc ARGV::OrDATA
You can also look for information at:
lib/ARGV/OrDATA.pm view on Meta::CPAN
@ARGV = 'file2.txt'; # Works.
my $from_file2 = <>;
Calling C<import> after C<unimport> would restore the DATA handle, but
B<wouldn't rewind it>, i.e. it would continue from where you stopped
(see t/04-unimport.t).
=head2 Why?
I use this technique when solving programming contests. The sample
input is usually small and I don't want to waste time by saving it
into a file.
=head1 EXPORT
Nothing. There are 2 subroutines you can call via their fully qualified names,
though:
=over 4
t/00-data.t view on Meta::CPAN
#!/usr/bin/perl
use warnings;
use strict;
use Test::More tests => 3;
use FindBin;
open *STDIN, '<&', IO::Pty->new
if ! -t && eval { require IO::Pty };
SKIP: {
skip "Can't run the test when stdin is not the terminal", 3
unless -t;
my $PIPE;
if ('MSWin32' eq $^O && $] < 5.022) {
open $PIPE, '-|', "$^X $FindBin::Bin/script.pl" or die $!;
} else {
open $PIPE, '-|', $^X, "$FindBin::Bin/script.pl" or die $!;
}
is $_, "data $.\n", "Read line $. from DATA" while <$PIPE>;
t/01-file.t view on Meta::CPAN
#!/usr/bin/perl
use warnings;
use strict;
use Test::More tests => 3;
use FindBin;
my $PIPE;
if ('MSWin32' eq $^O && $] < 5.022) {
open $PIPE, '-|', "$^X $FindBin::Bin/script.pl $FindBin::Bin/input.txt"
or die $!;
} else {
open $PIPE, '-|', $^X, "$FindBin::Bin/script.pl",
"$FindBin::Bin/input.txt"
t/03-package.t view on Meta::CPAN
#!/usr/bin/perl
use warnings;
use strict;
use Test::More tests => 3;
use FindBin;
use lib $FindBin::Bin;
use My;
BEGIN {
open *STDIN, '<&', IO::Pty->new
if ! -t && eval { require IO::Pty };
}
use ARGV::OrDATA qw{ My };
SKIP: {
skip "Can't run the test when stdin is not the terminal", 3
unless -t;
is $_, "package $.\n", "Read line $. from package" while <>;
ok eof, 'end of package';
}
__DATA__
data 1
data 2
t/04-unimport.t view on Meta::CPAN
#!/usr/bin/perl
use warnings;
use strict;
use Test::More tests => 4;
use FindBin;
BEGIN {
open *STDIN, '<&', IO::Pty->new
if ! -t && eval { require IO::Pty };
}
use ARGV::OrDATA;
SKIP: {
skip "Can't run the test when stdin is not the terminal", 4
unless -t;
my $file = "$FindBin::Bin/input.txt";
is scalar <>, "data 1\n", 'read line 1 from data';
@ARGV = $file;
is scalar <>, "data 2\n", 'changes to @ARGV ignored';
'ARGV::OrDATA'->unimport;
t/05-is_funcs.t view on Meta::CPAN
#!/usr/bin/perl
use warnings;
use strict;
use FindBin;
use Test::More tests => 4;
my %SCRIPT = (0 => 'is_using.pl',
1 => 'is_using_package.pl');
sub run {
my ($argument, $package, $expected) = @_;
my $PIPE;
if ('MSWin32' eq $^O && $] < 5.022) {
open $PIPE, '-|',
"$^X $FindBin::Bin/$SCRIPT{$package}"
. ($argument ? "$FindBin::Bin/input.txt" : "")
#!/usr/bin/perl
use warnings;
use strict;
use Test::More tests => 3;
use ARGV::OrDATA;
while (<>) {
is $_, "pipe $.\n", "read line $. from stdin";
}
ok eof *STDIN, 'end of stdin';
__DATA__
data 1
xt/changes.t view on Meta::CPAN
#!/usr/bin/perl
use warnings;
use strict;
use Test::More tests => 1;
use ARGV::OrDATA;
use FindBin;
my $module_version = $ARGV::OrDATA::VERSION;
my $dir = $FindBin::Bin . '/..';
open my $changes, '<', "$dir/Changes" or die 'Changes not found';
my $found;
xt/pod-coverage.t view on Meta::CPAN
#!perl -T
use 5.006;
use strict;
use warnings;
use Test::More;
# Ensure a recent version of Test::Pod::Coverage
my $min_tpc = 1.08;
eval "use Test::Pod::Coverage $min_tpc";
plan skip_all => "Test::Pod::Coverage $min_tpc required for testing POD coverage"
if $@;
# Test::Pod::Coverage doesn't require a minimum Pod::Coverage version,
# but older versions don't recognize some common documentation styles
my $min_pc = 0.18;
eval "use Pod::Coverage $min_pc";
plan skip_all => "Pod::Coverage $min_pc required for testing POD coverage"
if $@;
all_pod_coverage_ok();
#!perl -T
use 5.006;
use strict;
use warnings;
use Test::More;
# Ensure a recent version of Test::Pod
my $min_tp = 1.22;
eval "use Test::Pod $min_tp";
plan skip_all => "Test::Pod $min_tp required for testing POD" if $@;
all_pod_files_ok();
( run in 0.351 second using v1.01-cache-2.11-cpan-496ff517765 )