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