line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Ubic::ServiceLoader; |
2
|
|
|
|
|
|
|
$Ubic::ServiceLoader::VERSION = '1.58_01'; # TRIAL |
3
|
|
|
|
|
|
|
# ABSTRACT: load service from file |
4
|
|
|
|
|
|
|
|
5
|
25
|
|
|
25
|
|
27658
|
use strict; |
|
25
|
|
|
|
|
41
|
|
|
25
|
|
|
|
|
840
|
|
6
|
25
|
|
|
25
|
|
100
|
use warnings; |
|
25
|
|
|
|
|
67
|
|
|
25
|
|
|
|
|
885
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
25
|
|
|
25
|
|
123
|
use Params::Validate qw(:all); |
|
25
|
|
|
|
|
33
|
|
|
25
|
|
|
|
|
4103
|
|
10
|
25
|
|
|
25
|
|
147
|
use File::Basename; |
|
25
|
|
|
|
|
43
|
|
|
25
|
|
|
|
|
1992
|
|
11
|
25
|
|
|
25
|
|
8025
|
use Ubic::ServiceLoader::Default; |
|
25
|
|
|
|
|
49
|
|
|
25
|
|
|
|
|
14855
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my %ext2loader; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub ext2loader { |
16
|
1
|
|
|
1
|
1
|
2
|
my $class = shift; |
17
|
1
|
|
|
|
|
28
|
my ($ext) = validate_pos(@_, { type => SCALAR, regex => qr/^\w+$/ }); |
18
|
|
|
|
|
|
|
|
19
|
1
|
50
|
|
|
|
24
|
return $ext2loader{$ext} if $ext2loader{$ext}; |
20
|
1
|
|
|
|
|
554
|
require "Ubic/ServiceLoader/Ext/$ext.pm"; # TODO - improve error message if ext.pm doesn't exist |
21
|
1
|
|
|
|
|
5
|
my $loader_class = "Ubic::ServiceLoader::Ext::$ext"; |
22
|
1
|
|
|
|
|
9
|
return $loader_class->new; |
23
|
|
|
|
|
|
|
# FIXME - cache loader_class! |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub split_service_filename { |
27
|
46
|
|
|
46
|
1
|
68
|
my $class = shift; |
28
|
46
|
|
|
|
|
363
|
my ($filename) = validate_pos(@_, 1); |
29
|
|
|
|
|
|
|
|
30
|
46
|
|
|
|
|
336
|
my ($service_name, $ext) = $filename =~ /^ |
31
|
|
|
|
|
|
|
([\w-]+) |
32
|
|
|
|
|
|
|
(?: \.(\w+) )? |
33
|
|
|
|
|
|
|
$/x; |
34
|
46
|
|
|
|
|
252
|
return ($service_name, $ext); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub load { |
38
|
29
|
|
|
29
|
1
|
54
|
my $class = shift; |
39
|
29
|
|
|
|
|
258
|
my ($file) = validate_pos(@_, 1); |
40
|
|
|
|
|
|
|
|
41
|
29
|
|
|
|
|
1839
|
my $filename = basename($file); |
42
|
29
|
|
|
|
|
139
|
my ($service_name, $ext) = $class->split_service_filename($filename); |
43
|
29
|
50
|
|
|
|
114
|
die "Invalid filename '$file'" unless defined $service_name; |
44
|
|
|
|
|
|
|
|
45
|
29
|
|
|
|
|
47
|
my $loader; |
46
|
29
|
100
|
|
|
|
99
|
if ($ext) { |
47
|
1
|
|
|
|
|
5
|
$loader = $class->ext2loader($ext); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
else { |
50
|
28
|
|
|
|
|
276
|
$loader = Ubic::ServiceLoader::Default->new; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
29
|
|
|
|
|
106
|
my $service = $loader->load($file); |
54
|
29
|
|
|
|
|
322
|
return $service; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
1; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
__END__ |