Barfing content to output file.
Perl
Switch branches/tags
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
doc
examples
inc/Module
t
xt/IO-Barf
.gitignore
Barf.pm
Changes
LICENSE
MANIFEST
MANIFEST.SKIP
META.yml
Makefile.PL
README
SIGNATURE
TODO

README

NAME
    IO::Barf - Barfing content to output file.

SYNOPSIS
     use IO::Barf qw(barf);
     barf($file_or_handler, 'CONTENT');

SUBROUTINES
    "barf($file_or_handler, $content)"
             Barf content to file or handler.

ERRORS
     barf():
             Cannot open file '%s'.
             Cannot close file '%s'.
             Unsupported reference '%s'.

EXAMPLE1
     # Pragmas.
     use strict;
     use warnings;

     # Module.
     use File::Temp;
     use IO::Barf;

     # Content.
     my $content = "foo\nbar\n";

     # Temporary file.
     my $temp_file = File::Temp->new->filename;

     # Barf out.
     barf($temp_file, $content);

     # Print tempory file.
     system "cat $temp_file";

     # Unlink temporary file.
     unlink $temp_file;

     # Output:
     # foo
     # bar

EXAMPLE2
     # Pragmas.
     use strict;
     use warnings;

     # Module.
     use IO::Barf;

     # Content.
     my $content = "foo\nbar\n";

     # Barf out.
     barf(\*STDOUT, $content);

     # Output:
     # foo
     # bar

EXAMPLE3
     # Pragmas.
     use strict;
     use warnings;

     # Module.
     use Benchmark qw(cmpthese);
     use IO::All;
     use IO::Any;
     use IO::Barf;
     use File::Slurp qw(write_file);
     use File::Temp;
     use Path::Tiny;

     # Temporary files.
     my $temp1 = File::Temp->new->filename;
     my $temp2 = File::Temp->new->filename;
     my $temp3 = File::Temp->new->filename;
     my $temp4 = File::Temp->new->filename;
     my $temp5 = File::Temp->new->filename;

     # Some data.
     my $data = 'x' x 1000;

     # Benchmark (10s).
     cmpthese(-10, {
             'File::Slurp' => sub {
                     write_file($temp3, $data);
                     unlink $temp3;
             },
             'IO::All' => sub {
                     $data > io($temp4);
                     unlink $temp4;
             },
             'IO::Any' => sub {
                     IO::Any->spew($temp2, $data);
                     unlink $temp2;
             },
             'IO::Barf' => sub {
                     barf($temp1, $data);
                     unlink $temp1;
             },
             'Path::Tiny' => sub {
                     path($temp5)->spew($data);
                     unlink $temp5;
             },
     });

     # Output like this:
     #                Rate  Path::Tiny     IO::Any     IO::All File::Slurp    IO::Barf
     # Path::Tiny   3210/s          --        -17%        -51%        -85%        -91%
     # IO::Any      3859/s         20%          --        -41%        -82%        -89%
     # IO::All      6574/s        105%         70%          --        -70%        -81%
     # File::Slurp 21615/s        573%        460%        229%          --        -39%
     # IO::Barf    35321/s       1000%        815%        437%         63%          --

EXAMPLE4
     # Pragmas.
     use strict;
     use warnings;

     # Module.
     use Benchmark qw(cmpthese);
     use File::Temp;

     # Temporary files.
     my $temp1 = File::Temp->new->filename;
     my $temp2 = File::Temp->new->filename;
     my $temp3 = File::Temp->new->filename;
     my $temp4 = File::Temp->new->filename;
     my $temp5 = File::Temp->new->filename;

     # Some data.
     my $data = 'x' x 1000;

     # Benchmark (10s).
     cmpthese(-10, {
             'File::Slurp' => sub {
                     require File::Slurp;
                     File::Slurp::write_file($temp3, $data);
                     unlink $temp3;
             },
             'IO::All' => sub {
                     require IO::All;
                     $data > io($temp4);
                     unlink $temp4;
             },
             'IO::Any' => sub {
                     require IO::Any;
                     IO::Any->spew($temp2, $data);
                     unlink $temp2;
             },
             'IO::Barf' => sub {
                     require IO::Barf;
                     barf($temp1, $data);
                     unlink $temp1;
             },
             'Path::Tiny' => sub {
                     require Path::Tiny;
                     path($temp5)->spew($data);
                     unlink $temp5;
             },
     });

     # Output like this:
     # TODO

DEPENDENCIES
    Error::Pure, Exporter, Readonly, Scalar::Util.

SEE ALSO
    IO::Any
        open anything

    File::Slurp
        Simple and Efficient Reading/Writing/Modifying of Complete Files

    Perl6::Slurp
        Implements the Perl 6 'slurp' built-in

REPOSITORY
    <https://github.com/tupinek/IO-Barf>

AUTHOR
    Michal Špaček <mailto:skim@cpan.org>

    <http://skim.cz>

LICENSE AND COPYRIGHT
     © 2009-2015 Michal Špaček
     BSD 2-Clause License

VERSION
    0.08