| 1 | package MoobX::Trait::Observable; | ||||||||||
| 2 | 9 | our $AUTHORITY = 'cpan:YANICK'; | |||||||||
| 3 | # ABSTRACT: turn a Moose object attribute into an MoobX observable | ||||||||||
| 4 | 9 | $MoobX::Trait::Observable::VERSION = '0.1.2'; | |||||||||
| 5 | |||||||||||
| 6 | 9 | ▶ | use Moose::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 9 | ▶ | use MoobX; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 9 | ▶ | use Moose::Util; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 9 | Moose::Util::meta_attribute_alias('Observable'); | |||||||||
| 11 | |||||||||||
| 12 | 9 | ▶ | use experimental 'signatures'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 1 | ▶ | after initialize_instance_slot => sub($attr_self,$,$instance,$) { | ||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.3
| |||||||||||
| 15 | |||||||||||
| 16 | 3 | ▶ | $instance->meta->add_before_method_modifier( $attr_self->get_read_method, sub($self,@) { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||
| 17 | 3 | ▶ | push @MoobX::DEPENDENCIES, $attr_self if $MoobX::WATCHING; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 18 | 1 | ▶ | }) if $attr_self->has_read_method; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 19 | |||||||||||
| 20 | 3 | ▶ | $instance->meta->add_after_method_modifier( $attr_self->get_write_method, sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
| |||||||||||
| 21 | 3 | my( $self, $value ) = @_; | |||||||||
| 22 | 3 | ▶ | MoobX::observable_ref($value) if ref $value; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | 3 | MoobX::observable_modified( $attr_self ); | |||||||||
| 24 | 1 | ▶ | }) if $attr_self->has_write_method; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 25 | |||||||||||
| 26 | 9 | }; | |||||||||
| 27 | |||||||||||
| 28 | 9 | 1; | |||||||||
| 29 | |||||||||||
| 30 | __END__ | ||||||||||