blib/lib/Ubic/ServiceLoader/Default.pm untested

filter: Statementstmt 0.0% 0 / 33 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 4 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 51 SCAR 30.0
CC
4
Cov
0%
load
20.0
new
2.0
BEGIN
2.0
CRAP 20.0
1 package Ubic::ServiceLoader::Default;
2 $Ubic::ServiceLoader::Default::VERSION = '1.59';
3 # ABSTRACT: default service loader
4  
5 use strict;
6 use warnings;
7  
8 use parent qw( Ubic::ServiceLoader::Base );
9  
10  
11 use Scalar::Util qw(blessed);
12  
13 my $eval_id = 1;
14  
15 sub new {
16 return bless {} => shift;
17 }
18  
19 sub load {
20 my $self = shift;
21 my ($file) = @_;
22  
23 open my $fh, '<', $file or die "Can't open $file: $!";
24 my $content = do { local $/; <$fh> };
25 close $fh or die "Can't close $file: $!";
26  
27 $content = "# line 1 $file\n$content";
28 $content = "package UbicService".($eval_id++).";\n# line 1 $file\n$content";
29 my $service = eval $content;
30 if ($@) {
31 die "Failed to eval '$file': $@";
32 }
33 unless (blessed $service) {
34 die "$file doesn't contain any service";
35 }
36 unless ($service->isa('Ubic::Service')) {
37 die "$file returned $service instead of Ubic::Service";
38 }
39 return $service;
40 }
41  
42 1;
43  
44 __END__