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   140565 use base qw(Exporter);
  3         20  
  3         384  
4 3     3   21 use strict;
  3         7  
  3         57  
5 3     3   16 use warnings;
  3         6  
  3         103  
6              
7 3     3   953 use Error::Pure qw(err);
  3         22863  
  3         82  
8 3     3   116 use Readonly;
  3         7  
  3         133  
9 3     3   18 use Scalar::Util qw(blessed);
  3         6  
  3         802  
10              
11             # Constants.
12             Readonly::Array our @EXPORT => qw(barf);
13              
14             # Version.
15             our $VERSION = 0.08;
16              
17             # Barf content to file.
18             sub barf {
19 12     12 1 22791 my ($file_or_handler, $content) = @_;
20              
21             # File.
22 12         29 my $ref = ref $file_or_handler;
23 12 100 100     108 if (! $ref) {
    100          
    100          
24 4 50       179 open my $ouf, '>', $file_or_handler
25             or err "Cannot open file '$file_or_handler'.";
26 4         12 print {$ouf} $content;
  4         18  
27 4 50       238 close $ouf or err "Cannot close file '$file_or_handler'.";
28              
29             # Handler
30             } elsif ($ref eq 'GLOB') {
31 3         6 print {$file_or_handler} $content;
  3         13  
32              
33             # IO::Handle.
34             } elsif (blessed($file_or_handler)
35             && $file_or_handler->isa('IO::Handle')) {
36              
37 3         13 $file_or_handler->print($content);
38              
39             # Other.
40             } else {
41 2         13 err "Unsupported reference '$ref'.";
42             }
43              
44 10         53 return;
45             }
46              
47             1;
48              
49             __END__