lib/Ubic/ServiceLoader/Default.pm

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