line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package RapidApp::Module::Meta::Trait::ExtProp; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Attribute Trait for Ext config properties (EXPERIMENTAL) |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
|
6
|
5
|
|
|
5
|
|
31
|
use Moose::Role; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
42
|
|
7
|
|
|
|
|
|
|
Moose::Util::meta_attribute_alias('ExtProp'); |
8
|
|
|
|
|
|
|
|
9
|
5
|
|
|
5
|
|
21721
|
use RapidApp::Util ':all'; |
|
5
|
|
|
|
|
13
|
|
|
5
|
|
|
|
|
3233
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# Same as the attribute name by default, but allow override: |
13
|
|
|
|
|
|
|
has 'ext_name', is => 'ro', isa => 'Str', lazy => 1, default => sub { (shift)->name }; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub get_ext_value { |
16
|
466
|
|
|
466
|
0
|
1014
|
my ($attr, $obj) = @_; |
17
|
|
|
|
|
|
|
|
18
|
466
|
|
|
|
|
1623
|
my $value = $attr->get_value($obj); |
19
|
|
|
|
|
|
|
|
20
|
466
|
100
|
66
|
|
|
61413
|
if($attr->has_type_constraint && $attr->type_constraint->equals('Bool')) { |
21
|
462
|
50
|
|
|
|
76143
|
return $value ? \1 : \0; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
4
|
|
|
|
|
858
|
return $value |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub _apply_ext_value { |
29
|
466
|
|
|
466
|
|
45817
|
my ($attr, $obj) = @_; |
30
|
466
|
|
|
|
|
13481
|
$obj->apply_extconfig( $attr->ext_name => $attr->get_ext_value($obj) ) |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# Hook all events which set the value and automatically apply |
34
|
|
|
|
|
|
|
# to the extconfig of the object/instance |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
after 'set_initial_value' => sub { (shift)->_apply_ext_value(@_) }; |
37
|
|
|
|
|
|
|
after 'set_raw_value' => sub { (shift)->_apply_ext_value(@_) }; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
1; |