File Coverage

lib/Ubic/ServiceLoader/Default.pm
Criterion Covered Total %
statement 27 30 90.0
branch 5 10 50.0
condition n/a
subroutine 6 6 100.0
pod 2 2 100.0
total 40 48 83.3


line stmt bran cond sub pod time code
1             package Ubic::ServiceLoader::Default;
2             $Ubic::ServiceLoader::Default::VERSION = '1.58_01'; # TRIAL
3             # ABSTRACT: default service loader
4              
5 25     25   30901 use strict;
  25         32  
  25         778  
6 25     25   126 use warnings;
  25         30  
  25         804  
7              
8 25     25   131 use parent qw( Ubic::ServiceLoader::Base );
  25         30  
  25         157  
9              
10              
11 25     25   1479 use Scalar::Util qw(blessed);
  25         30  
  25         7239  
12              
13             my $eval_id = 1;
14              
15             sub new {
16 29     29 1 146 return bless {} => shift;
17             }
18              
19             sub load {
20 29     29 1 63 my $self = shift;
21 29         55 my ($file) = @_;
22              
23 29 50       1327 open my $fh, '<', $file or die "Can't open $file: $!";
24 29         67 my $content = do { local $/; <$fh> };
  29         186  
  29         715  
25 29 50       406 close $fh or die "Can't close $file: $!";
26              
27 29         133 $content = "# line 1 $file\n$content";
28 29         169 $content = "package UbicService".($eval_id++).";\n# line 1 $file\n$content";
29 29         12399 my $service = eval $content;
30 29 50       139 if ($@) {
31 0         0 die "Failed to eval '$file': $@";
32             }
33 29 50       189 unless (blessed $service) {
34 0         0 die "$file doesn't contain any service";
35             }
36 29 50       318 unless ($service->isa('Ubic::Service')) {
37 0         0 die "$file returned $service instead of Ubic::Service";
38             }
39 29         198 return $service;
40             }
41              
42             1;
43              
44             __END__