ARGV-OrDATA

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

ARGV-OrDATA

ARGV::OrDATA - Let the diamond operator read from DATA if there's no ARGV

SYNOPSIS

    use ARGV::OrDATA;

    while (<>) {
        print;
    }

    __DATA__
    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:

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

        *ARGV eq *{$package . '::DATA' }
    }
}


=head1 SYNOPSIS

    use ARGV::OrDATA;

    while (<>) {
        print;
    }

    __DATA__
    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.

=head1 DESCRIPTION

Tell your script it should use the DATA section if there's no input
coming from STDIN and there are no arguments.

You can also specify which package's DATA should be read instead of
the caller's:

    use My::Module;
    use ARGV::OrDATA 'My::Module';

    while (<>) {  # This reads from My/Module.pm's DATA section.
        print;
    }

To restore the old behaviour, you can call the C<unimport> method.

    use ARGV::OrDATA;

    my $from_data = <>;

    @ARGV = 'file1.txt';  # Ignored.

t/02-stdin.t  view on Meta::CPAN


use FindBin;

my $PIPE;
if ('MSWin32' eq $^O && $] < 5.022) {
    open $PIPE, '|-', "$^X $FindBin::Bin/pipe.pl" or die $!;
} else {
    open $PIPE, '|-', $^X, "$FindBin::Bin/pipe.pl" or die $!;
}

print {$PIPE} << '__PIPE__';
pipe 1
pipe 2
__PIPE__
close $PIPE;

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/script.pl  view on Meta::CPAN

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

use ARGV::OrDATA;

while (<>) {
    print;
}

__DATA__
data 1
data 2



( run in 0.791 second using v1.01-cache-2.11-cpan-de7293f3b23 )