File Coverage

blib/lib/IO/Barf.pm
Criterion Covered Total %
statement 30 30 100.0
branch 8 10 80.0
condition 3 3 100.0
subroutine 7 7 100.0
pod 1 1 100.0
total 49 51 96.0


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