ARGV-OrDATA

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

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.

MANIFEST  view on Meta::CPAN

Changes
lib/ARGV/OrDATA.pm
Makefile.PL
MANIFEST			This list of files
README
t/00-data.t
t/01-file.t
t/02-stdin.t
t/03-package.t
t/04-unimport.t
t/05-is_funcs.t
t/input.txt
t/My.pm
t/pipe.pl
t/script.pl
t/is_using.pl
t/is_using_package.pl
xt/changes.t
xt/manifest.t
xt/pod-coverage.t
xt/pod.t
META.yml                                 Module YAML meta-data (added by MakeMaker)
META.json                                Module JSON meta-data (added by MakeMaker)

META.json  view on Meta::CPAN

      },
      "runtime" : {
         "requires" : {
            "perl" : "5.008"
         }
      }
   },
   "release_status" : "stable",
   "resources" : {
      "repository" : {
         "url" : "https://github.com/choroba/argv-ordata"
      }
   },
   "version" : "0.005",
   "x_serialization_backend" : "JSON::PP version 2.27400_02"
}

META.yml  view on Meta::CPAN

  url: http://module-build.sourceforge.net/META-spec-v1.4.html
  version: '1.4'
name: ARGV-OrDATA
no_index:
  directory:
    - t
    - inc
requires:
  perl: '5.008'
resources:
  repository: https://github.com/choroba/argv-ordata
version: '0.005'
x_serialization_backend: 'CPAN::Meta::YAML version 0.018'

Makefile.PL  view on Meta::CPAN

        'Test::More' => '0',
    },
    PREREQ_PM => {
        #'ABC'              => '1.6',
        #'Foo::Bar::Module' => '5.0401',
    },
    macro => { TARFLAGS => '--format=ustar -cvf' },
    dist  => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
    clean => { FILES => 'ARGV-OrDATA-*' },
    META_MERGE => {
        resources => { repository => 'https://github.com/choroba/argv-ordata' },
    },
);

README  view on Meta::CPAN

perldoc command.

    perldoc ARGV::OrDATA

You can also look for information at:

    MetaCPAN
        https://metacpan.org/pod/ARGV::OrDATA

    GitHub, the distribution's git repository (inludes issues)
        http://github.com/choroba/argv-ordata


LICENSE AND COPYRIGHT

Copyright (C) 2017 E. Choroba

This program is free software; you can redistribute it and/or modify it
under the terms of the the Artistic License (2.0). You may obtain a
copy of the full license at:

lib/ARGV/OrDATA.pm  view on Meta::CPAN

    my $package = shift;
    *ARGV = *ORIG;
    {   no strict 'refs';
        delete ${$package . '::'}{ORIG};
    }
    undef *ORIG;
}


sub is_using_argv {
    ! is_using_data()
}


sub is_using_data {
    my ($package) = caller;
    $package = caller 1 if 'ARGV::OrDATA' eq $package;
    return do {
        no strict 'refs';
        *ARGV eq *{$package . '::DATA' }
    }
}


=head1 SYNOPSIS

t/00-data.t  view on Meta::CPAN

    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>;

    ok eof $PIPE, 'closed DATA';
}

t/03-package.t  view on Meta::CPAN

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

}

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;
    @ARGV = $file;
    is scalar <>, "file 1\n", 'unimport works';

    'ARGV::OrDATA'->import;
    is scalar <>, "data 3\n", 'switching back to data';
}

__DATA__
data 1
data 2
data 3

t/05-is_funcs.t  view on Meta::CPAN

            or die $!;
    } else {
        open $PIPE, '-|', $^X, "$FindBin::Bin/$SCRIPT{$package}",
                               $argument ? "$FindBin::Bin/input.txt" : ()
            or die $!;
    }

    chomp( my $output = <$PIPE> );

    is $output, $expected, join ' ', $package ? 'package' : 'main',
                                     $argument ? 'argv' : 'data';
}

run(1, 0, '10');
run(0, 0, '01');
run(1, 1, '10');
run(0, 1, '01');

t/is_using.pl  view on Meta::CPAN

#!/usr/bin/perl
use warnings;
use strict;

use ARGV::OrDATA;

print ARGV::OrDATA::is_using_argv() ? 1 : 0;
print ARGV::OrDATA::is_using_data() ? 1 : 0;
print "\n";

__DATA__
1

t/is_using_package.pl  view on Meta::CPAN

#!/usr/bin/perl
use warnings;
use strict;

package
    My;

use ARGV::OrDATA;

print ARGV::OrDATA::is_using_argv() ? 1 : 0;
print ARGV::OrDATA::is_using_data() ? 1 : 0;
print "\n";

__DATA__
1

t/pipe.pl  view on Meta::CPAN

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
data 2

t/script.pl  view on Meta::CPAN

use warnings;
use strict;

use ARGV::OrDATA;

while (<>) {
    print;
}

__DATA__
data 1
data 2

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 0.743 second using v1.00-cache-2.02-grep-82fe00e-cpan-4673cadbf75 )