ARGV-OrDATA

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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.

README  view on Meta::CPAN

14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
    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

91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
    @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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/perl
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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/usr/bin/perl
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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/perl
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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/perl
use strict;
 
use Test::More tests => 4;
 
use FindBin;
 
BEGIN {
    open *STDIN, '<&', IO::Pty->new
        if ! -t && eval { require IO::Pty };
}
 
 
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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/usr/bin/perl
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" : "")

t/pipe.pl  view on Meta::CPAN

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/usr/bin/perl
use strict;
 
use Test::More tests => 3;
 
 
while (<>) {
    is $_, "pipe $.\n", "read line $. from stdin";
}
ok eof *STDIN, 'end of stdin';
 
__DATA__
data 1

xt/changes.t  view on Meta::CPAN

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/usr/bin/perl
use strict;
 
use Test::More tests => 1;
 
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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!perl -T
use 5.006;
use strict;
 
# 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();

xt/pod.t  view on Meta::CPAN

1
2
3
4
5
6
7
8
9
10
11
12
#!perl -T
use 5.006;
use strict;
 
# 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 )