File Coverage

blib/lib/BLOB.pm
Criterion Covered Total %
statement 22 26 84.6
branch 4 6 66.6
condition n/a
subroutine 7 7 100.0
pod 3 3 100.0
total 36 42 85.7


line stmt bran cond sub pod time code
1             package BLOB;
2 1     1   605 use strict;
  1         2  
  1         43  
3 1     1   7 use Carp qw(carp);
  1         3  
  1         74  
4 1     1   6 use Exporter ();
  1         6  
  1         289  
5              
6             # No "our" in Perl 5.0
7 1     1   10 use vars qw(@ISA $VERSION @EXPORT);
  1         1  
  1         388  
8              
9             $VERSION = '1.01';
10             @ISA = qw(Exporter);
11             @EXPORT = qw(mark_blob is_blob);
12              
13             # Fallback for Perl < 5.8
14             *utf8::downgrade = sub { 1 } if not defined &utf8::downgrade;
15              
16             # Class method
17             sub mark {
18 2     2 1 4 my $class = shift;
19 2         4 my $blob_ref = \shift;
20 2 50       10 if (not utf8::downgrade($$blob_ref, 1)) {
21 0         0 carp "Wide character outside byte range in BLOB, encoding data with UTF-8";
22 0         0 utf8::encode($$blob_ref);
23             }
24 2         11 bless $blob_ref, $class;
25             }
26              
27             # Function
28             sub mark_blob {
29 1     1 1 31 BLOB->mark($_[0]);
30             }
31              
32             # Function
33             sub is_blob {
34 6     6 1 9 my $blob_ref = \shift;
35 6 100       9 return undef if not eval { $blob_ref->isa('BLOB') };
  6         52  
36 2 50       9 if (not utf8::downgrade($$blob_ref, 1)) {
37 0         0 carp "Wide character outside byte range in BLOB, encoding data with UTF-8";
38 0         0 utf8::encode($$blob_ref);
39             }
40 2         6 return 1;
41             }
42              
43             1;
44              
45             __END__