| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package IO::Barf; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 3 |  |  | 3 |  | 120836 | use base qw(Exporter); | 
|  | 3 |  |  |  |  | 18 |  | 
|  | 3 |  |  |  |  | 361 |  | 
| 4 | 3 |  |  | 3 |  | 17 | use strict; | 
|  | 3 |  |  |  |  | 4 |  | 
|  | 3 |  |  |  |  | 48 |  | 
| 5 | 3 |  |  | 3 |  | 10 | use warnings; | 
|  | 3 |  |  |  |  | 5 |  | 
|  | 3 |  |  |  |  | 87 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 | 3 |  |  | 3 |  | 868 | use Error::Pure qw(err); | 
|  | 3 |  |  |  |  | 20422 |  | 
|  | 3 |  |  |  |  | 85 |  | 
| 8 | 3 |  |  | 3 |  | 111 | use Readonly; | 
|  | 3 |  |  |  |  | 7 |  | 
|  | 3 |  |  |  |  | 116 |  | 
| 9 | 3 |  |  | 3 |  | 16 | use Scalar::Util qw(blessed); | 
|  | 3 |  |  |  |  | 5 |  | 
|  | 3 |  |  |  |  | 695 |  | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | # Constants. | 
| 12 |  |  |  |  |  |  | Readonly::Array our @EXPORT => qw(barf); | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | our $VERSION = 0.09; | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | # Barf content to file. | 
| 17 |  |  |  |  |  |  | sub barf { | 
| 18 | 12 |  |  | 12 | 1 | 19960 | my ($file_or_handler, $content) = @_; | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | # File. | 
| 21 | 12 |  |  |  |  | 25 | my $ref = ref $file_or_handler; | 
| 22 | 12 | 100 | 100 |  |  | 71 | if (! $ref) { | 
|  |  | 100 |  |  |  |  |  | 
|  |  | 100 |  |  |  |  |  | 
| 23 | 4 | 50 |  |  |  | 158 | open my $ouf, '>', $file_or_handler | 
| 24 |  |  |  |  |  |  | or err "Cannot open file '$file_or_handler'."; | 
| 25 | 4 |  |  |  |  | 9 | print {$ouf} $content; | 
|  | 4 |  |  |  |  | 15 |  | 
| 26 | 4 | 50 |  |  |  | 226 | close $ouf or err "Cannot close file '$file_or_handler'."; | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | # Handler | 
| 29 |  |  |  |  |  |  | } elsif ($ref eq 'GLOB') { | 
| 30 | 3 |  |  |  |  | 6 | print {$file_or_handler} $content; | 
|  | 3 |  |  |  |  | 9 |  | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | # IO::Handle. | 
| 33 |  |  |  |  |  |  | } elsif (blessed($file_or_handler) | 
| 34 |  |  |  |  |  |  | && $file_or_handler->isa('IO::Handle')) { | 
| 35 |  |  |  |  |  |  |  | 
| 36 | 3 |  |  |  |  | 12 | $file_or_handler->print($content); | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | # Other. | 
| 39 |  |  |  |  |  |  | } else { | 
| 40 | 2 |  |  |  |  | 11 | err "Unsupported reference '$ref'."; | 
| 41 |  |  |  |  |  |  | } | 
| 42 |  |  |  |  |  |  |  | 
| 43 | 10 |  |  |  |  | 44 | return; | 
| 44 |  |  |  |  |  |  | } | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | 1; | 
| 47 |  |  |  |  |  |  |  | 
| 48 |  |  |  |  |  |  | __END__ |