line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Ubic::ServiceLoader; |
2
|
|
|
|
|
|
|
$Ubic::ServiceLoader::VERSION = '1.59'; |
3
|
|
|
|
|
|
|
# ABSTRACT: load service from file |
4
|
|
|
|
|
|
|
|
5
|
23
|
|
|
23
|
|
24549
|
use strict; |
|
23
|
|
|
|
|
31
|
|
|
23
|
|
|
|
|
573
|
|
6
|
23
|
|
|
23
|
|
77
|
use warnings; |
|
23
|
|
|
|
|
39
|
|
|
23
|
|
|
|
|
557
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
23
|
|
|
23
|
|
75
|
use Params::Validate qw(:all); |
|
23
|
|
|
|
|
22
|
|
|
23
|
|
|
|
|
2685
|
|
10
|
23
|
|
|
23
|
|
100
|
use File::Basename; |
|
23
|
|
|
|
|
28
|
|
|
23
|
|
|
|
|
1085
|
|
11
|
23
|
|
|
23
|
|
5329
|
use Ubic::ServiceLoader::Default; |
|
23
|
|
|
|
|
31
|
|
|
23
|
|
|
|
|
9007
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my %ext2loader; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub ext2loader { |
16
|
1
|
|
|
1
|
1
|
2
|
my $class = shift; |
17
|
1
|
|
|
|
|
17
|
my ($ext) = validate_pos(@_, { type => SCALAR, regex => qr/^\w+$/ }); |
18
|
|
|
|
|
|
|
|
19
|
1
|
50
|
|
|
|
15
|
return $ext2loader{$ext} if $ext2loader{$ext}; |
20
|
1
|
|
|
|
|
263
|
require "Ubic/ServiceLoader/Ext/$ext.pm"; # TODO - improve error message if ext.pm doesn't exist |
21
|
1
|
|
|
|
|
3
|
my $loader_class = "Ubic::ServiceLoader::Ext::$ext"; |
22
|
1
|
|
|
|
|
6
|
return $loader_class->new; |
23
|
|
|
|
|
|
|
# FIXME - cache loader_class! |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub split_service_filename { |
27
|
41
|
|
|
41
|
1
|
41
|
my $class = shift; |
28
|
41
|
|
|
|
|
226
|
my ($filename) = validate_pos(@_, 1); |
29
|
|
|
|
|
|
|
|
30
|
41
|
|
|
|
|
183
|
my ($service_name, $ext) = $filename =~ /^ |
31
|
|
|
|
|
|
|
([\w-]+) |
32
|
|
|
|
|
|
|
(?: \.(\w+) )? |
33
|
|
|
|
|
|
|
$/x; |
34
|
41
|
|
|
|
|
149
|
return ($service_name, $ext); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub load { |
38
|
24
|
|
|
24
|
1
|
37
|
my $class = shift; |
39
|
24
|
|
|
|
|
164
|
my ($file) = validate_pos(@_, 1); |
40
|
|
|
|
|
|
|
|
41
|
24
|
|
|
|
|
1149
|
my $filename = basename($file); |
42
|
24
|
|
|
|
|
85
|
my ($service_name, $ext) = $class->split_service_filename($filename); |
43
|
24
|
50
|
|
|
|
66
|
die "Invalid filename '$file'" unless defined $service_name; |
44
|
|
|
|
|
|
|
|
45
|
24
|
|
|
|
|
31
|
my $loader; |
46
|
24
|
100
|
|
|
|
76
|
if ($ext) { |
47
|
1
|
|
|
|
|
3
|
$loader = $class->ext2loader($ext); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
else { |
50
|
23
|
|
|
|
|
187
|
$loader = Ubic::ServiceLoader::Default->new; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
24
|
|
|
|
|
85
|
my $service = $loader->load($file); |
54
|
24
|
|
|
|
|
202
|
return $service; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
1; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
__END__ |