blib/lib/Gapp/Meta/Widget/Native/Trait/ListFormField.pm untested

filter: Statementstmt 0.0% 0 / 36 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 52 CC 2 SCAR 10.6
CC
2
Cov
0%
set_field_value
6.0
get_field_value
2.0
widget_to_stash
2.0
CRAP 2.9
1 package Gapp::Meta::Widget::Native::Trait::ListFormField;
2 {
3 $Gapp::Meta::Widget::Native::Trait::ListFormField::VERSION = '0.60';
4 }
5  
6 use Moose::Role;
7 use MooseX::SemiAffordanceAccessor;
8 with 'Gapp::Meta::Widget::Native::Role::FormField';
9  
10  
11 has 'value_column' => (
12 is => 'rw',
13 isa => 'Int',
14 default => 0,
15 );
16  
17  
18 # returns the value of the widget
19 sub get_field_value {
20 my $self = shift;
21
22 my $model = $self->gobject->get_model;
23 my $iter = $model->get_iter_first;
24
25 my @values;
26 while ( $iter ) {
27 my $o = $model->get( $iter, $self->value_column );
28 $iter = $model->iter_next( $iter );
29 push @values, $o;
30 }
31
32 return \@values;
33 }
34  
35 sub set_field_value {
36 my ( $self, $value ) = @_;
37
38 my $model = $self->gobject->get_model;
39 $model->clear;
40
41 if ( $value ) {
42 $model->append( $_ ) for @$value;
43 }
44 }
45  
46 sub widget_to_stash {
47 my ( $self, $stash ) = @_;
48 $stash->store( $self->field, $self->get_field_value );
49 }
50  
51 sub stash_to_widget {
52 my ( $self, $stash ) = @_;
53 $self->set_field_value( $stash->fetch( $self->field ) );
54 }
55  
56 sub _connect_changed_handler {
57 my ( $self ) = @_;
58
59  
60 $self->gobject->get_model->signal_connect (
61 row_inserted => sub { $self->_widget_value_changed },
62 );
63 $self->gobject->get_model->signal_connect (
64 row_deleted => sub { $self->_widget_value_changed },
65 );
66 }
67  
68  
69 package Gapp::Meta::Widget::Custom::Trait::ListFormField;
70 {
71 $Gapp::Meta::Widget::Custom::Trait::ListFormField::VERSION = '0.60';
72 }
73 sub register_implementation { 'Gapp::Meta::Widget::Native::Trait::ListFormField' };
74  
75  
76 1;