line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:YANICK'; |
2
|
|
|
|
|
|
|
# ABSTRACT: turn a Moose object attribute into an MoobX observable |
3
|
|
|
|
|
|
|
$MoobX::Trait::Observable::VERSION = '0.1.1'; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
use Moose::Role; |
6
|
8
|
|
|
8
|
|
3449
|
use MoobX; |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
42
|
|
7
|
8
|
|
|
8
|
|
34431
|
use Moose::Util; |
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
68
|
|
8
|
8
|
|
|
8
|
|
608
|
|
|
8
|
|
|
|
|
13
|
|
|
8
|
|
|
|
|
48
|
|
9
|
|
|
|
|
|
|
Moose::Util::meta_attribute_alias('Observable'); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use experimental 'signatures'; |
12
|
8
|
|
|
8
|
|
1395
|
|
|
8
|
|
|
|
|
32
|
|
|
8
|
|
|
|
|
45
|
|
13
|
|
|
|
|
|
|
after initialize_instance_slot => sub($attr_self,$,$instance,$) { |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
$instance->meta->add_before_method_modifier( $attr_self->get_read_method, sub($self,@) { |
16
|
|
|
|
|
|
|
push @MoobX::DEPENDENCIES, $attr_self if $MoobX::WATCHING; |
17
|
|
|
|
|
|
|
}) if $attr_self->has_read_method; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
$instance->meta->add_after_method_modifier( $attr_self->get_write_method, sub { |
20
|
|
|
|
|
|
|
my( $self, $value ) = @_; |
21
|
|
|
|
|
|
|
MoobX::observable_ref($value) if ref $value; |
22
|
|
|
|
|
|
|
MoobX::observable_modified( $attr_self ); |
23
|
|
|
|
|
|
|
}) if $attr_self->has_write_method; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
}; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
1; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=pod |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=encoding UTF-8 |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 NAME |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
MoobX::Trait::Observable - turn a Moose object attribute into an MoobX observable |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 VERSION |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
version 0.1.1 |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 SYNOPSIS |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
package Person; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
use MoobX; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
our $OPENING :Observable = 'Dear'; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
has name => ( |
51
|
|
|
|
|
|
|
traits => [ 'Observable' ], |
52
|
|
|
|
|
|
|
is => 'rw', |
53
|
|
|
|
|
|
|
); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
has address => ( |
56
|
|
|
|
|
|
|
is => 'ro', |
57
|
|
|
|
|
|
|
traits => [ 'Observer' ], |
58
|
|
|
|
|
|
|
default => sub { |
59
|
|
|
|
|
|
|
my $self = shift; |
60
|
|
|
|
|
|
|
join ' ', $Person::OPENING, $self->name |
61
|
|
|
|
|
|
|
}, |
62
|
|
|
|
|
|
|
); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
my $person = Person->new( name => 'Wilfred' ); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
print $person->address; # Dear Wilfred |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
$person->name( 'Wilma' ); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
print $person->address; # Dear Wilma |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 DESCRIPTION |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Turns an object attribute into an observable. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 AUTHOR |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Yanick Champoux <yanick@cpan.org> |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
This software is copyright (c) 2022, 2017 by Yanick Champoux. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
85
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=cut |