line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Ubic::ServiceLoader; |
2
|
|
|
|
|
|
|
$Ubic::ServiceLoader::VERSION = '1.60'; |
3
|
|
|
|
|
|
|
# ABSTRACT: load service from file |
4
|
|
|
|
|
|
|
|
5
|
23
|
|
|
23
|
|
21938
|
use strict; |
|
23
|
|
|
|
|
25
|
|
|
23
|
|
|
|
|
530
|
|
6
|
23
|
|
|
23
|
|
61
|
use warnings; |
|
23
|
|
|
|
|
39
|
|
|
23
|
|
|
|
|
456
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
23
|
|
|
23
|
|
69
|
use Params::Validate qw(:all); |
|
23
|
|
|
|
|
24
|
|
|
23
|
|
|
|
|
2444
|
|
10
|
23
|
|
|
23
|
|
87
|
use File::Basename; |
|
23
|
|
|
|
|
24
|
|
|
23
|
|
|
|
|
898
|
|
11
|
23
|
|
|
23
|
|
5138
|
use Ubic::ServiceLoader::Default; |
|
23
|
|
|
|
|
28
|
|
|
23
|
|
|
|
|
7710
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my %ext2loader; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub ext2loader { |
16
|
1
|
|
|
1
|
1
|
1
|
my $class = shift; |
17
|
1
|
|
|
|
|
16
|
my ($ext) = validate_pos(@_, { type => SCALAR, regex => qr/^\w+$/ }); |
18
|
|
|
|
|
|
|
|
19
|
1
|
50
|
|
|
|
14
|
return $ext2loader{$ext} if $ext2loader{$ext}; |
20
|
1
|
|
|
|
|
257
|
require "Ubic/ServiceLoader/Ext/$ext.pm"; # TODO - improve error message if ext.pm doesn't exist |
21
|
1
|
|
|
|
|
2
|
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
|
49
|
my $class = shift; |
28
|
41
|
|
|
|
|
193
|
my ($filename) = validate_pos(@_, 1); |
29
|
|
|
|
|
|
|
|
30
|
41
|
|
|
|
|
180
|
my ($service_name, $ext) = $filename =~ /^ |
31
|
|
|
|
|
|
|
([\w-]+) |
32
|
|
|
|
|
|
|
(?: \.(\w+) )? |
33
|
|
|
|
|
|
|
$/x; |
34
|
41
|
|
|
|
|
135
|
return ($service_name, $ext); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub load { |
38
|
24
|
|
|
24
|
1
|
36
|
my $class = shift; |
39
|
24
|
|
|
|
|
143
|
my ($file) = validate_pos(@_, 1); |
40
|
|
|
|
|
|
|
|
41
|
24
|
|
|
|
|
1157
|
my $filename = basename($file); |
42
|
24
|
|
|
|
|
70
|
my ($service_name, $ext) = $class->split_service_filename($filename); |
43
|
24
|
50
|
|
|
|
60
|
die "Invalid filename '$file'" unless defined $service_name; |
44
|
|
|
|
|
|
|
|
45
|
24
|
|
|
|
|
20
|
my $loader; |
46
|
24
|
100
|
|
|
|
62
|
if ($ext) { |
47
|
1
|
|
|
|
|
3
|
$loader = $class->ext2loader($ext); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
else { |
50
|
23
|
|
|
|
|
179
|
$loader = Ubic::ServiceLoader::Default->new; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
24
|
|
|
|
|
76
|
my $service = $loader->load($file); |
54
|
24
|
|
|
|
|
153
|
return $service; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
1; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
__END__ |