File Coverage

blib/lib/Starch/Util.pm
Criterion Covered Total %
statement 28 28 100.0
branch 2 2 100.0
condition 1 2 50.0
subroutine 9 9 100.0
pod 2 2 100.0
total 42 43 97.6


line stmt bran cond sub pod time code
1             package Starch::Util;
2 14     14   208391 use 5.008001;
  14         64  
3 14     14   81 use strictures 2;
  14         147  
  14         568  
4             our $VERSION = '0.11';
5              
6             =head1 NAME
7              
8             Starch::Util - Utility functions used internally by Starch.
9              
10             =cut
11              
12 14     14   3110 use Carp qw();
  14         40  
  14         407  
13 14     14   561 use Module::Runtime qw( require_module is_module_name );
  14         1796  
  14         114  
14 14     14   6922 use Module::Find qw( findallmod );
  14         17890  
  14         839  
15              
16 14     14   6124 use namespace::clean;
  14         158512  
  14         116  
17              
18 14     14   3820 use Exporter qw( import );
  14         31  
  14         2825  
19             our @EXPORT_OK;
20              
21             =head1 FUNCTIONS
22              
23             =head2 croak
24              
25             This is a custom L C function which sets various
26             standard starch packages as C so that Carp looks
27             deeper in the stack for something to blame which makes exceptions
28             be more contextually useful for users of Starch and means we don't
29             need to use confess which generates giant stack traces.
30              
31             =cut
32              
33             my $all_modules;
34              
35             push @EXPORT_OK, 'croak';
36             sub croak {
37 9   50 9 1 136 $all_modules ||= [ findallmod('Starch') ];
38 9         123086 local @Carp::Internal{@$all_modules} = map { 1 } @$all_modules;
  234         517  
39 9         1971 return Carp::croak( @_ );
40             }
41              
42             =head2 load_prefixed_module
43              
44             # These both return "Foo::Bar".
45             my $module = load_prefixed_module( 'Foo', '::Bar' );
46             my $module = load_prefixed_module( 'Foo', 'Foo::Bar' );
47              
48             Takes a prefix to be appended to a relative package name and a
49             relative or absolute package name. It then resolves the relative
50             package name to an absolute one, loads it, and returns the
51             absolute name.
52              
53             =cut
54              
55             push @EXPORT_OK, 'load_prefixed_module';
56             sub load_prefixed_module {
57 234     234 1 16245 my ($prefix, $module) = @_;
58              
59 234 100       1122 $module = "$prefix$module" if $module =~ m{^::};
60              
61 234         867 require_module( $module );
62              
63 233         5535 return $module;
64             }
65              
66             1;
67             __END__