line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Nitesi::Provider::Object; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
20314
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
57
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
require Exporter; |
7
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
8
|
|
|
|
|
|
|
our @EXPORT_OK = qw(api_object); |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
467
|
use Nitesi::Class; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
468
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head2 api_object |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Creates an API object. |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=cut |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub api_object { |
19
|
1
|
|
|
1
|
1
|
12
|
my (%args) = @_; |
20
|
1
|
|
|
|
|
2
|
my ($api_class, $api_object, $settings_class, $backend, $sname, $provider, |
21
|
|
|
|
|
|
|
$provider_settings, $o_settings, $backend_settings, @roles, |
22
|
|
|
|
|
|
|
$settings, @settings_args); |
23
|
|
|
|
|
|
|
|
24
|
1
|
|
|
|
|
3
|
$backend = $args{backend}; |
25
|
1
|
|
50
|
|
|
9
|
$backend_settings = $args{backend_settings} || {}; |
26
|
1
|
|
|
|
|
3
|
$api_class = $args{class}; |
27
|
1
|
|
|
|
|
2
|
$settings = $args{settings}; |
28
|
|
|
|
|
|
|
|
29
|
1
|
50
|
|
|
|
5
|
if (exists $args{name}) { |
30
|
1
|
|
|
|
|
4
|
$sname = ucfirst($args{name}); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# check whether base class for this object is overridden in the settings |
33
|
1
|
50
|
|
|
|
10
|
if (exists $settings->{$sname}->{class}) { |
34
|
0
|
|
|
|
|
0
|
$api_class = $settings->{$sname}->{class}; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# create API object |
39
|
1
|
|
|
|
|
2
|
my (%api_info, $o_key); |
40
|
|
|
|
|
|
|
|
41
|
1
|
|
|
|
|
11
|
$api_object = Nitesi::Class->instantiate($api_class, |
42
|
|
|
|
|
|
|
api_class => $api_class, |
43
|
|
|
|
|
|
|
api_name => $args{name}, |
44
|
|
|
|
|
|
|
); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# add API attributes after instantiation |
47
|
1
|
|
|
|
|
18
|
$api_object->api_attributes($settings->{$sname}->{attributes}); |
48
|
|
|
|
|
|
|
|
49
|
1
|
50
|
|
|
|
10
|
unless ($api_object) { |
50
|
0
|
|
|
|
|
0
|
die "Failed to create class $api_class: $@"; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
1
|
|
|
|
|
6
|
$api_info{$api_class} = $api_object->api_info; |
54
|
1
|
|
|
|
|
4
|
$o_key = $api_info{$api_class}->{key}; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# load roles for this API object |
57
|
1
|
50
|
|
|
|
2
|
for my $role_name (@{$args{roles} || []}) { |
|
1
|
|
|
|
|
10
|
|
58
|
0
|
|
|
|
|
0
|
Nitesi::Class->load($role_name); |
59
|
0
|
|
|
|
|
0
|
my $api_func = lc($role_name); |
60
|
0
|
|
|
|
|
0
|
$api_func =~ s/^(.*)::([^:]+)$/$2/; |
61
|
0
|
|
|
|
|
0
|
$api_func .= '_api_info'; |
62
|
0
|
|
|
|
|
0
|
$api_info{$role_name} = $role_name->$api_func; |
63
|
0
|
|
|
|
|
0
|
push (@roles, $role_name); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
1
|
|
|
|
|
2
|
my ($key, $value); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# load backend class |
69
|
1
|
50
|
|
|
|
4
|
if ($backend) { |
70
|
0
|
|
|
|
|
0
|
my $backend_class = "Nitesi::Backend::$backend"; |
71
|
0
|
|
|
|
|
0
|
Nitesi::Class->load($backend_class); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# apply backend role to navigation object |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
0
|
Moo::Role->apply_roles_to_object($api_object, @roles, $backend_class); |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
0
|
while (($key, $value) = each %$backend_settings) { |
78
|
0
|
|
|
|
|
0
|
$api_object->$key($value); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
1
|
50
|
|
|
|
6
|
if ($settings->{$sname}->{field_map}) { |
83
|
0
|
|
|
|
|
0
|
$api_object->field_map($settings->{$sname}->{field_map}); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
1
|
|
|
|
|
5
|
$api_object->api_info(\%api_info); |
87
|
|
|
|
|
|
|
|
88
|
1
|
50
|
|
|
|
6
|
if ($args{$o_key}) { |
89
|
0
|
|
|
|
|
0
|
$api_object->$o_key($args{$o_key}); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
1
|
50
|
|
|
|
4
|
if ($args{record}) { |
93
|
0
|
|
|
|
|
0
|
while (($key, $value) = each %{$args{record}}) { |
|
0
|
|
|
|
|
0
|
|
94
|
0
|
|
|
|
|
0
|
$api_object->$key($value); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
1
|
|
|
|
|
9
|
return $api_object; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |