| 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
| |||||||||||
| 24 | 974 | my $content = do { local $/; <$fh> }; | |||||||||
| 25 | 974 | ▶ | close $fh or die "Can't close $file: $!"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 31 | 3 | die "Failed to eval '$file': $@"; | |||||||||
| 32 | } | ||||||||||
| 33 | 971 | ▶ | unless (blessed $service) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | 0 | die "$file doesn't contain any service"; | |||||||||
| 35 | } | ||||||||||
| 36 | 971 | ▶ | unless ($service->isa('Ubic::Service')) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | 0 | die "$file returned $service instead of Ubic::Service"; | |||||||||
| 38 | } | ||||||||||
| 39 | 971 | return $service; | |||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | 154 | 1; | |||||||||
| 43 | |||||||||||
| 44 | __END__ | ||||||||||