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   135866 use base qw(Exporter);
  3         4  
  3         321  
4 3     3   12 use strict;
  3         7  
  3         50  
5 3     3   8 use warnings;
  3         3  
  3         115  
6              
7 3     3   790 use Error::Pure qw(err);
  3         17486  
  3         66  
8 3     3   128 use Readonly;
  3         6  
  3         100  
9 3     3   10 use Scalar::Util qw(blessed);
  3         9  
  3         756  
10              
11             # Constants.
12             Readonly::Array our @EXPORT => qw(barf);
13              
14             our $VERSION = 0.12;
15              
16             # Barf content to file.
17             sub barf {
18 12     12 1 265826 my ($file_or_handler, $content) = @_;
19              
20             # File.
21 12         43 my $ref = ref $file_or_handler;
22 12 100 100     89 if (! $ref) {
    100          
    100          
23 4 50       178 open my $ouf, '>', $file_or_handler
24             or err "Cannot open file '$file_or_handler'.";
25 4         5 print {$ouf} $content;
  4         15  
26 4 50       362 close $ouf or err "Cannot close file '$file_or_handler'.";
27              
28             # Handler
29             } elsif ($ref eq 'GLOB') {
30 3         4 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         9 $file_or_handler->print($content);
37              
38             # Other.
39             } else {
40 2         15 err "Unsupported reference '$ref'.";
41             }
42              
43 10         42 return;
44             }
45              
46             1;
47              
48             __END__