ConnectProperties/Element/child.pm untested

filter: Statementstmt 0.0% 0 / 36 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 66 CC 2 SCAR 10.0
CC
2
Cov
0%
set_value
6.0
check_property
2.0
find_property
2.0
CRAP 2.7
1 # Copyright 2010, 2011, 2012 Kevin Ryde
2  
3 # This file is part of Glib-Ex-ConnectProperties.
4 #
5 # Glib-Ex-ConnectProperties is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License as published
7 # by the Free Software Foundation; either version 3, or (at your option) any
8 # later version.
9 #
10 # Glib-Ex-ConnectProperties is distributed in the hope that it will be
11 # useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
13 # Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with Glib-Ex-ConnectProperties. If not, see <http://www.gnu.org/licenses/>.
17  
18 package Glib::Ex::ConnectProperties::Element::child;
19 use 5.008;
20 use strict;
21 use warnings;
22 use Carp;
23 use base 'Glib::Ex::ConnectProperties::Element';
24  
25 our $VERSION = 20;
26  
27 # uncomment this to run the ### lines
28 #use Smart::Comments;
29  
30 sub check_property {
31 my ($self) = @_;
32 ### Element-child check_property()
33  
34 # check find_child_property() method exists, to avoid a slew of errors
35 # later when attempting to set
36 Gtk2::Container->can('find_child_property') # wrapped in Perl-Gtk2 1.240
37 || croak 'ConnectProperties: No Gtk2::Container find_child_property() in this Perl-Gtk';
38  
39 # and that the property exists initially
40 $self->SUPER::check_property();
41 }
42  
43 # Base is_readable() / is_writable() are true if no find_property() pspec.
44 # Always read/write in case no parent or no such property. But for now
45 # demanding the widget be in a parent with the property initially.
46 #
47 # use constant is_readable => 1;
48 # use constant is_writable => 1;
49  
50 sub find_property {
51 my ($self) = @_;
52 ### Element-child find_property()
53 my $parent;
54 return (($parent = $self->{'object'}->get_parent)
55 && $parent->find_child_property ($self->{'pname'}));
56 }
57  
58 sub read_signal {
59 my ($self) = @_;
60 return ('child-notify::' . $self->{'pname'});
61 }
62  
63 sub get_value {
64 my ($self) = @_;
65 ### Element-child get_value(): $self->{'pname'}
66 ### parent: $self->{'object'}->get_parent
67 my $object = $self->{'object'};
68 my $parent;
69 return (($parent = $object->get_parent)
70 && $parent->child_get_property ($object, $self->{'pname'}));
71 }
72 sub set_value {
73 my ($self, $value) = @_;
74 ### Element-child set_value(): $self->{'pname'}, $value
75 ### parent: $self->{'object'}->get_parent
76 my $object = $self->{'object'};
77 if (my $parent = $object->get_parent) {
78 $parent->child_set_property ($object, $self->{'pname'}, $value);
79 }
80 }
81  
82 1;
83 __END__