File Coverage

blib/lib/Refinements.pm
Criterion Covered Total %
statement 33 33 100.0
branch 3 6 50.0
condition 2 5 40.0
subroutine 9 9 100.0
pod n/a
total 47 53 88.6


line stmt bran cond sub pod time code
1 1     1   28007 use 5.010;
  1         4  
  1         53  
2 1     1   6 use strict;
  1         1  
  1         41  
3 1     1   5 use warnings;
  1         7  
  1         41  
4              
5             {
6             package Refinements;
7            
8 1     1   1065 use Exporter::Tiny ();
  1         2727  
  1         24  
9 1     1   1185 use Module::Runtime qw( module_notional_filename );
  1         1860  
  1         10  
10            
11             our $AUTHORITY = 'cpan:TOBYINK';
12             our $VERSION = '0.001';
13             our @EXPORT = qw( refine );
14             our @ISA = qw( Exporter::Tiny );
15            
16             sub _exporter_validate_opts
17             {
18 1     1   45 my $class = shift;
19 1         2 my ($opt) = @_;
20            
21 1 50 33     10 defined($opt->{into}) && !ref($opt->{into})
22             or Exporter::Tiny::_croak('Cannot set up %s as a Refinements::Package', $opt->{into});
23            
24 1   50     4 $INC{module_notional_filename($opt->{into})} ||= __FILE__;
25            
26 1         606 require Refinements::Package;
27 1     1   157 no strict 'refs';
  1         2  
  1         195  
28 1         3 push @{ $opt->{into} . '::ISA' }, 'Refinements::Package';
  1         21  
29             }
30            
31             sub _generate_refine
32             {
33 1     1   77 my $class = shift;
34 1         2 my ($name, $value, $opt) = @_;
35            
36 1         3 my $collection = $opt->{into};
37            
38             return sub {
39 1 50   1   110 @_ >= 2
40             or Exporter::Tiny::_croak('Expected at least 2 arguments to refine(); got %d', scalar @_);
41 1         3 my $coderef = pop;
42 1 50       2 $collection->add_refinement($_, $coderef) for map { ref($_) ? @$_ : $_ } @_;
  1         9  
43 1         9 };
44             }
45             }
46              
47             1;
48              
49             __END__