ARGV-OrDATA
view release on metacpan or search on metacpan
12345678910111213141516Revision 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.
141516171819202122232425262728293031323334
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
919293949596979899100101102103104105106107108109110
@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
1234567891011121314151617181920212223#!/usr/bin/perl
use
warnings;
use
strict;
use
FindBin;
open
*STDIN
,
'<&'
, IO::Pty->new
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
t/03-package.t view on Meta::CPAN
123456789101112131415161718192021222324252627282930
t/04-unimport.t view on Meta::CPAN
123456789101112131415161718192021222324252627#!/usr/bin/perl
use
warnings;
use
strict;
use
FindBin;
BEGIN {
open
*STDIN
,
'<&'
, IO::Pty->new
}
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
12345678910111213141516#!/usr/bin/perl
use
warnings;
use
strict;
use
FindBin;
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"
:
""
)
123456789101112131415#!/usr/bin/perl
use
warnings;
use
strict;
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
123456789101112131415#!/usr/bin/perl
use
warnings;
use
strict;
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
1234567891011121314151617181920#!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();
123456789101112#!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.344 second using v1.01-cache-2.11-cpan-2b0bae70ee8 )