File Coverage

blib/lib/ETL/Yertl/Util.pm
Criterion Covered Total %
statement 21 22 95.4
branch 6 8 75.0
condition n/a
subroutine 4 4 100.0
pod 1 1 100.0
total 32 35 91.4


line stmt bran cond sub pod time code
1             package ETL::Yertl::Util;
2             our $VERSION = '0.035';
3             # ABSTRACT: Utility functions for Yertl modules
4              
5             #pod =head1 SYNOPSIS
6             #pod
7             #pod =head1 DESCRIPTION
8             #pod
9             #pod =head1 SEE ALSO
10             #pod
11             #pod =cut
12              
13 21     21   149 use ETL::Yertl;
  21         41  
  21         92  
14 21     21   639 use Exporter qw( import );
  21         38  
  21         534  
15 21     21   98 use Module::Runtime qw( use_module compose_module_name );
  21         30  
  21         124  
16              
17             our @EXPORT_OK = qw(
18             load_module
19             );
20              
21             #pod =sub load_module
22             #pod
23             #pod $class = load_module( format => $format );
24             #pod $class = load_module( protocol => $proto );
25             #pod $class = load_module( database => $db );
26             #pod
27             #pod Load a module of the given type with the given name. Throws an exception if the
28             #pod module is not found or the module cannot be loaded.
29             #pod
30             #pod This function should be used to load modules that the user requests. The error
31             #pod messages are suitable for user consumption.
32             #pod
33             #pod =cut
34              
35             sub load_module {
36 244     244 1 607 my ( $type, $name ) = @_;
37              
38 244 50       567 die "$type is required\n" unless $name;
39 244         386 my $class = eval { compose_module_name( 'ETL::Yertl::' . ucfirst $type, $name ) };
  244         1059  
40 244 100       10789 if ( $@ ) {
41 1         5 die "Unknown $type '$name'\n";
42             }
43              
44 243         418 eval {
45 243         597 use_module( $class );
46             };
47 243 100       6478 if ( $@ ) {
48 1 50       5 if ( $@ =~ /^Can't locate \S+ in \@INC/ ) {
49 1         6 die "Unknown $type '$name'\n";
50             }
51 0         0 die "Could not load $type '$name': $@";
52             }
53              
54 242         1298 return $class;
55             }
56              
57             1;
58              
59             __END__