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   149636 use base qw(Exporter);
  3         22  
  3         380  
4 3     3   21 use strict;
  3         5  
  3         57  
5 3     3   14 use warnings;
  3         4  
  3         109  
6              
7 3     3   1026 use Error::Pure qw(err);
  3         24034  
  3         82  
8 3     3   117 use Readonly;
  3         6  
  3         136  
9 3     3   18 use Scalar::Util qw(blessed);
  3         6  
  3         868  
10              
11             # Constants.
12             Readonly::Array our @EXPORT => qw(barf);
13              
14             our $VERSION = 0.10;
15              
16             # Barf content to file.
17             sub barf {
18 12     12 1 24220 my ($file_or_handler, $content) = @_;
19              
20             # File.
21 12         28 my $ref = ref $file_or_handler;
22 12 100 100     94 if (! $ref) {
    100          
    100          
23 4 50       196 open my $ouf, '>', $file_or_handler
24             or err "Cannot open file '$file_or_handler'.";
25 4         13 print {$ouf} $content;
  4         18  
26 4 50       279 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         14  
31              
32             # IO::Handle.
33             } elsif (blessed($file_or_handler)
34             && $file_or_handler->isa('IO::Handle')) {
35              
36 3         17 $file_or_handler->print($content);
37              
38             # Other.
39             } else {
40 2         13 err "Unsupported reference '$ref'.";
41             }
42              
43 10         53 return;
44             }
45              
46             1;
47              
48             __END__