blib/lib/Gapp/Meta/Widget/Native/Role/FormField.pm untested

filter: Statementstmt 0.0% 0 / 36 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 81 CC 7 SCAR 30.5
CC
7
Cov
0%
_widget_value_changed
42.0
update
6.0
enable
2.0
CRAP 21.1
1 package Gapp::Meta::Widget::Native::Role::FormField;
2 {
3 $Gapp::Meta::Widget::Native::Role::FormField::VERSION = '0.60';
4 }
5  
6 use Moose::Role;
7 use MooseX::SemiAffordanceAccessor;
8 with 'Gapp::Meta::Widget::Native::Role::FormElement';
9  
10 # the field name to use when storing the value
11 has 'field' => (
12 is => 'rw',
13 isa => 'Maybe[Str]',
14 default => undef,
15 );
16  
17 # is true if the widget is currently being updated
18 # used to prevent recursive updates
19 has 'is_updating' => (
20 is => 'rw',
21 isa => 'Bool',
22 default => 0,
23 );
24  
25 # called after a fields value is changed
26 has 'on_change' => (
27 is => 'rw',
28 isa => 'CodeRef|Undef',
29 );
30  
31 # block the on_change handler
32 has 'block_on_change' => (
33 is => 'rw',
34 isa => 'Bool',
35 default => 0,
36 );
37  
38  
39 sub _widget_value_changed {
40 my ( $self ) = @_; # $self = the form field
41 return if $self->is_updating;
42
43 my $form = $self->form;
44
45 if ( $form && $self->field ) {
46 $self->widget_to_stash( $form->stash );
47
48 if ( $self->field && $form->sync && $form->context ) {
49 $form->context->modify( $self->field, $form->stash->fetch( $self->field ) )
50 }
51 }
52 if ( ! $self->block_on_change && ! $self->is_updating ) {
53 $self->on_change->( $self ) if $self->on_change;
54 }
55
56 }
57  
58 before _apply_signals => sub {
59 my ( $self ) = @_;
60 $self->_connect_changed_handler if $self->can('_connect_changed_handler');
61 };
62  
63 sub update {
64 my ( $self ) = @_;
65 $self->set_is_updating( 1 );
66 $self->stash_to_widget( $self->form->stash ) if $self->field;
67 $self->set_is_updating( 0 );
68 }
69  
70  
71 sub enable {
72 my ( $self ) = @_;
73 $self->gobject->set_sensitive( 1 );
74 }
75  
76 sub disable {
77 my ( $self ) = @_;
78 $self->gobject->set_sensitive( 0 );
79 }
80  
81  
82  
83 package Gapp::Meta::Widget::Custom::Trait::FormField;
84 {
85 $Gapp::Meta::Widget::Custom::Trait::FormField::VERSION = '0.60';
86 }
87 sub register_implementation { 'Gapp::Meta::Widget::Native::Role::FormField' };
88  
89  
90 1;