File Coverage

lib/unmocked.pm
Criterion Covered Total %
statement 19 19 100.0
branch 5 6 83.3
condition n/a
subroutine 4 4 100.0
pod n/a
total 28 29 96.5


line stmt bran cond sub pod time code
1             package unmocked;
2 2     2   13 use strict;
  2         4  
  2         202  
3 2     2   22 use warnings;
  2         5  
  2         59  
4 2     2   13 use mocked;
  2         4  
  2         468  
5              
6             =head1 NAME
7              
8             unmocked - use real libraries from within mocked libraries
9              
10             =head1 SYNOPSIS
11              
12             # Your mocked module needs to use a real library
13             package Fake::Fun;
14             use unmocked 'URI';
15              
16             =head1 DESCRIPTION
17              
18             When mocking modules using 'mocked', you are certain that no extra "real"
19             libraries are being loaded. But sometimes you don't want to use real
20             libraries from within your mocked library. This module allows you to load
21             real libraries using your previous include paths.
22              
23             =cut
24              
25             our $VERSION = '0.01';
26              
27             =head1 FUNCTIONS
28              
29             =head2 import
30              
31             With a package name, this function will ensure that the module you specify
32             is loaded from the regular @INC path (that mocked.pm has removed).
33              
34             =cut
35              
36             sub import {
37 5     5   422 my $class = shift;
38 5         9 my $module = shift;
39 5 100       181 return unless $module;
40            
41             {
42 3         11 local @INC = @$mocked::real_inc_paths;
  3         20  
43 3         450 eval "require $module";
44             }
45 3 50       22225 die $@ if $@;
46              
47 3         43 my $import = $module->can('import');
48 3         35 @_ = ($module, @_);
49 3 100       247 goto &$import if $import;
50             }
51              
52             =head1 AUTHOR
53              
54             Luke Closs, C<< <cpan at 5thplane.com> >>
55              
56             =head1 LICENSE
57              
58             This program is free software; you can redistribute it and/or modify it
59             under the same terms as Perl itself.
60              
61             =cut
62              
63             1;