File Coverage

blib/lib/bare.pm
Criterion Covered Total %
statement 22 22 100.0
branch 4 6 66.6
condition 2 3 66.6
subroutine 5 5 100.0
pod n/a
total 33 36 91.6


line stmt bran cond sub pod time code
1             #!/usr/bin/perl -w
2              
3 2     2   23434 use strict;
  2         4  
  2         72  
4 2     2   9 use warnings;
  2         4  
  2         798  
5              
6             package bare;
7              
8             our $VERSION = '0.02';
9              
10             my %forbidden = map { $_ => 1 } qw(
11             if else elsif unless while until for foreach continue redo
12             q qq tr y m s qr qw qx
13             defined delete do eval exists format glob goto grep last local
14             map my next no our package print printf prototype redo require
15             return scalar sort split study sub undef use
16             given when break
17             );
18              
19             sub import {
20 2     2   1332 my $class = shift;
21 2         6 my $caller = caller;
22 2 100 66     20 my $legal_var = $utf8::hint_bits && $^H & $utf8::hint_bits
23             ? qr/^[[:alpha:]_]\w{0,250}$/
24             : qr/^[a-z_][a-z0-9_]{0,250}$/i;
25 2     2   21 no strict 'refs';
  2         5  
  2         369  
26 2         5 foreach my $bare (@_) {
27 3 50       9 die "cannot override $bare" if $forbidden{$bare};
28 3 50       37 die "illegal name: $bare" if $bare !~ $legal_var;
29 3         3 my $scalar;
30 3         5 *{"${caller}::$bare"} = \$scalar;
  3         26  
31 3     9   14 *{"${caller}::$bare"} = sub():lvalue{ ${"${caller}::$bare"} };
  3         2269  
  9         927  
  9         66  
32             }
33             }
34              
35             1;
36              
37             __END__