ConnectProperties/Element.pm untested

filter: Statementstmt 0.0% 0 / 43 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 14 Podpod 0.0% 0 / 9 totaltotal 0.0% 0 / 83 CC 2 SCAR 9.3
CC
2
Cov
0%
check_property
6.0
new
2.0
find_property
2.0
CRAP 2.5
1 # Copyright 2010, 2011, 2012, 2014 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  
19  
20 # $elem->do_read_handler()
21 # Glib::Ex::ConnectProperties::do_read_handler(..., $elem)
22 # \&Glib::Ex::ConnectProperties::read_handler
23 #
24 # connect_signals()
25 # disconnect()
26  
27  
28 package Glib::Ex::ConnectProperties::Element;
29 use 5.008;
30 use strict;
31 use warnings;
32  
33 use Carp;
34 our @CARP_NOT = ('Glib::Ex::ConnectProperties');
35  
36 our $VERSION = 20;
37  
38 # uncomment this to run the ### lines
39 #use Smart::Comments;
40  
41  
42 sub new {
43 my $class = shift;
44 return bless { @_ }, $class;
45 }
46  
47 # default no properties
48 use constant pspec_hash => {};
49  
50 sub find_property {
51 my ($self) = @_;
52 return $self->pspec_hash->{$self->{'pname'}};
53 }
54 sub check_property {
55 my ($self) = @_;
56 ### Element check_property() ...
57 if (! defined $self->find_property) {
58 croak("ConnectProperties: ", $self->{'object'},
59 " has no property ", $self->{'pname'});
60 }
61 }
62  
63 # not documented yet
64 sub is_readable {
65 my ($self) = @_;
66 ### Element is_readable() ...
67 my $pspec;
68 return (! ($pspec = $self->find_property)
69 || ($pspec->get_flags & 'readable'));
70 }
71  
72 # not documented yet
73 sub is_writable {
74 my ($self) = @_;
75 ### Element is_writable() ...
76 my $pspec;
77 return (! ($pspec = $self->find_property)
78 || ($pspec->get_flags & 'writable'));
79 }
80  
81 # $self in signal data is a circular reference, but ConnectProperties
82 # disconnect() calls the disconnect() here to undo
83 #
84 # not documented yet
85 sub connect_signals {
86 my ($self) = @_;
87 ### Element connect_signals() ...
88 my $object = $self->{'object'};
89 my $ids = $self->{'ids'} = Glib::Ex::SignalIds->new ($object);
90 foreach my $signame (delete $self->{'read_signal'} || $self->read_signal) {
91 ### $signame
92 $ids->add ($object->signal_connect
93 ($signame,
94 \&Glib::Ex::ConnectProperties::_do_read_handler,
95 $self));
96 }
97 }
98  
99 # not documented yet
100 sub disconnect {
101 my ($self) = @_;
102 delete $self->{'ids'};
103 }
104  
105 sub get_value {
106 my ($self) = @_;
107 croak ("ConnectProperties: cannot get value from ", $self->{'object'},
108 " property '", $self->{'pname'}, "'");
109 }
110 sub set_value {
111 my ($self) = @_;
112 croak ("ConnectProperties: cannot set value on ", $self->{'object'},
113 " property '", $self->{'pname'}, "'");
114 }
115  
116 1;
117 __END__