blib/lib/Gapp/Widget.pm untested

filter: Statementstmt 0.0% 0 / 43 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 74 CC 6 SCAR 24.2
CC
6
Cov
0%
BUILDARGS
20.0
toplevel
12.0
gwrapper
2.0
CRAP 11.3
1 package Gapp::Widget;
2 {
3 $Gapp::Widget::VERSION = '0.60';
4 }
5  
6 use Moose;
7 use MooseX::SemiAffordanceAccessor;
8 use MooseX::StrictConstructor;
9 extends 'Gapp::Object';
10  
11 has '+gobject' => (
12 handles => [qw( destroy hide present show show_all )],
13 );
14  
15 has 'name' => (
16 is => 'rw',
17 isa => 'Str',
18 default => '',
19 );
20  
21 # if the widget should be homogenous
22 has 'homogeneous' => (
23 is => 'rw',
24 isa => 'Bool',
25 default => 0,
26 );
27  
28 # if the widget should expand its container
29 has 'expand' => (
30 is => 'rw',
31 isa => 'Bool',
32 default => 1 ,
33 );
34  
35 # if the widget should fill its container
36 has 'fill' => (
37 is => 'rw',
38 isa => 'Bool',
39 default => 1 ,
40 );
41  
42 # the grwapper wraps encapsulates a widget
43 has 'gwrapper' => (
44 is => 'rw',
45 isa => 'Maybe[Gtk2::Object]',
46 reader => 'get_gwrapper',
47 writer => 'set_gwrapper',
48 default => undef,
49 );
50  
51 sub gwrapper {
52 my ( $self ) = @_;
53 $self->get_gwrapper || $self->gobject;
54 };
55  
56  
57 # padding around widget in container
58 has 'padding' => (
59 is => 'rw',
60 isa => 'Int',
61 default => 0,
62 );
63  
64 # the parent is set when the widget is added
65 # to a container widget
66 has 'parent' => (
67 is => 'rw',
68 isa => 'Maybe[Gapp::Widget]',
69 weak_ref => 1,
70 );
71  
72 #has 'toplevel' => (
73 # is => 'rw',
74 # isa => 'Maybe[Gapp::Widget]',
75 # weak_ref => 1,
76 #);
77  
78 # tooltip to display
79 has 'tooltip' => (
80 is => 'rw',
81 isa => 'Maybe[Str]',
82 );
83  
84  
85  
86  
87  
88  
89 sub toplevel {
90 my ( $self ) = @_;
91 return $self if ! $self->parent;
92
93 $self->parent ? $self->parent->toplevel : $self;
94 }
95  
96  
97  
98  
99 sub BUILDARGS {
100 my $class = shift;
101 my %args = @_ == 1 && is_HashRef( $_[0] ) ? %{$_[0]} : @_;
102
103 if ( exists $args{alignment} ) {
104 $args{properties}{xalign} = $args{alignment}[0];
105 $args{properties}{yalign} = $args{alignment}[1];
106 delete $args{alignment};
107 }
108
109 # headers visible
110 for my $att ( qw(visible sensitive xalign yalign no_show_all) ) {
111 $args{properties}{$att} = delete $args{$att} if exists $args{$att};
112 }
113
114 __PACKAGE__->SUPER::BUILDARGS( %args );
115 }
116  
117  
118 # this stores a reference to the Gapp::Object within the Gtk2::Widget
119 # this is done so that if the only-references to the Gapp::Object
120 # go away before the Gtk2::Widget - the Gapp::Object is still
121 # available to reference in callbacks - when the Gtk2::Widget is
122 # destroyed, then the circular reference will be deleted as well
123  
124 after '_build_gobject' => sub {
125 my ( $self ) = @_;
126
127 if ( $self->gobject->isa('Gtk2::Widget') ) {
128 $self->gobject->{_gapp} = $self;
129 $_[0]->{_gapp} = undef;
130 }
131 };
132  
133  
134  
135
136  
137 1;
138  
139 __END__