line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package XAS::Apps::Service::Testd; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1177
|
use Template; |
|
1
|
|
|
|
|
13297
|
|
|
1
|
|
|
|
|
22
|
|
4
|
1
|
|
|
1
|
|
5
|
use JSON::XS; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
42
|
|
5
|
1
|
|
|
1
|
|
408
|
use Web::Machine; |
|
1
|
|
|
|
|
49408
|
|
|
1
|
|
|
|
|
26
|
|
6
|
1
|
|
|
1
|
|
404
|
use Plack::Builder; |
|
1
|
|
|
|
|
2931
|
|
|
1
|
|
|
|
|
61
|
|
7
|
1
|
|
|
1
|
|
400
|
use Plack::App::File; |
|
1
|
|
|
|
|
3207
|
|
|
1
|
|
|
|
|
24
|
|
8
|
1
|
|
|
1
|
|
5
|
use Plack::App::URLMap; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
15
|
|
9
|
1
|
|
|
1
|
|
4
|
use XAS::Service::Server; |
|
1
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
31
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use XAS::Class |
12
|
1
|
|
|
|
|
14
|
version => '0.01', |
13
|
|
|
|
|
|
|
base => 'XAS::Lib::App::Service', |
14
|
|
|
|
|
|
|
mixin => 'XAS::Lib::Mixins::Configs', |
15
|
|
|
|
|
|
|
filesystem => 'File', |
16
|
|
|
|
|
|
|
accessors => 'cfg', |
17
|
|
|
|
|
|
|
vars => { |
18
|
|
|
|
|
|
|
SERVICE_NAME => 'XAS_TESTD', |
19
|
|
|
|
|
|
|
SERVICE_DISPLAY_NAME => 'XAS test micro service', |
20
|
|
|
|
|
|
|
SERVICE_DESCRIPTION => 'This process is a test micro service' |
21
|
|
|
|
|
|
|
} |
22
|
1
|
|
|
1
|
|
4
|
; |
|
1
|
|
|
|
|
2
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
25
|
|
|
|
|
|
|
# Public Methods |
26
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub build_app { |
29
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# define base, name and description |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
my $base = $self->cfg->val('app', 'base', '/home/kevin/dev/XAS-Service/trunk/web'); |
34
|
0
|
|
|
|
|
|
my $name = $self->cfg->val('app', 'name', 'WEB Services'); |
35
|
0
|
|
|
|
|
|
my $description = $self->cfg->val('app', 'description', 'Test api using RESTFUL HAL-JSON'); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# Template config |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
my $config = { |
40
|
|
|
|
|
|
|
INCLUDE_PATH => File($base, 'root')->path, # or list ref |
41
|
|
|
|
|
|
|
INTERPOLATE => 1, # expand "$var" in plain text |
42
|
|
|
|
|
|
|
}; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# create various objects |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
my $template = Template->new($config); |
47
|
0
|
|
|
|
|
|
my $json = JSON::XS->new->utf8(); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# allow variables with preceeding _ |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
$Template::Stash::PRIVATE = undef; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# handlers, using URLMap for routing |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
my $builder = Plack::Builder->new(); |
56
|
0
|
|
|
|
|
|
my $urlmap = Plack::App::URLMap->new(); |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
$urlmap->mount('/' => Web::Machine->new( |
59
|
|
|
|
|
|
|
resource => 'XAS::Service::Resource', |
60
|
|
|
|
|
|
|
resource_args => [ |
61
|
|
|
|
|
|
|
alias => 'root', |
62
|
|
|
|
|
|
|
template => $template, |
63
|
|
|
|
|
|
|
json => $json, |
64
|
|
|
|
|
|
|
app_name => $name, |
65
|
|
|
|
|
|
|
app_description => $description |
66
|
|
|
|
|
|
|
] ) |
67
|
|
|
|
|
|
|
); |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# static files |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
$urlmap->mount('/js' => Plack::App::File->new( |
72
|
|
|
|
|
|
|
root => $base . '/root/js' ) |
73
|
|
|
|
|
|
|
); |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
$urlmap->mount('/css' => Plack::App::File->new( |
76
|
|
|
|
|
|
|
root => $base . '/root/css') |
77
|
|
|
|
|
|
|
); |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
$urlmap->mount('/yaml' => Plack::App::File->new( |
80
|
|
|
|
|
|
|
root => $base . '/root/yaml/yaml') |
81
|
|
|
|
|
|
|
); |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
return $builder->to_app($urlmap->to_app); |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub setup { |
88
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
my $interface = XAS::Service::Server->new( |
91
|
|
|
|
|
|
|
-alias => 'interface', |
92
|
|
|
|
|
|
|
-port => $self->cfg->val('system', 'port', 9507), |
93
|
|
|
|
|
|
|
-address => $self->cfg->val('system', 'address', 'localhost'), |
94
|
|
|
|
|
|
|
-app => $self->build_app, |
95
|
|
|
|
|
|
|
); |
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
$self->service->register('interface'); |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub main { |
102
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
$self->log->info_msg('startup'); |
105
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
|
$self->setup(); |
107
|
0
|
|
|
|
|
|
$self->service->run(); |
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
$self->log->info_msg('shutdown'); |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
114
|
|
|
|
|
|
|
# Private Methods |
115
|
|
|
|
|
|
|
# ---------------------------------------------------------------------- |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub init { |
118
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
119
|
|
|
|
|
|
|
|
120
|
0
|
|
|
|
|
|
my $self = $class->SUPER::init(@_); |
121
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
$self->load_config(); |
123
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
return $self; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
1; |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
__END__ |