ConnectProperties/Element/combobox_active.pm untested

filter: Statementstmt 0.0% 0 / 46 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 64 CC 1 SCAR 6.9
CC
1
Cov
0%
get_value
2.0
set_value
2.0
BEGIN
2.0
CRAP 2.0
1 # Copyright 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  
19 package Glib::Ex::ConnectProperties::Element::combobox_active;
20 use 5.008;
21 use strict;
22 use warnings;
23 use Carp;
24 use Glib;
25 use Gtk2;
26 use Gtk2::Ex::ComboBoxBits 32; # v.32 for get_active_text()
27  
28 use base 'Glib::Ex::ConnectProperties::Element';
29 our $VERSION = 20;
30  
31 # uncomment this to run the ### lines
32 #use Smart::Comments;
33  
34  
35 use constant pspec_hash =>
36 {
37 exists => Glib::ParamSpec->boolean ('has-active', # name
38 '', # nick
39 '', # blurb
40 0, # default, unused
41 'readable'), # read-only
42 iter => Glib::ParamSpec->boxed ('iter', # name
43 '', # nick
44 '', # blurb
45 'Gtk2::TreeIter', # obj type
46 Glib::G_PARAM_READWRITE),
47 path => Glib::ParamSpec->boxed ('path', # name
48 '', # nick
49 '', # blurb
50 'Gtk2::TreePath', # boxed type
51 Glib::G_PARAM_READWRITE),
52 text => Glib::ParamSpec->string ('text', # name
53 '', # nick
54 '', # blurb
55 '', # default
56 Glib::G_PARAM_READWRITE),
57 };
58  
59 use constant read_signal => 'changed';
60  
61 my %get_method = (exists => sub { !! $_[0]->get_active_iter },
62 iter => 'get_active_iter',
63 path => \&Gtk2::Ex::ComboBoxBits::get_active_path,
64 text => 'get_active_text',
65 );
66 sub get_value {
67 my ($self) = @_;
68 ### combobox_active get_value()
69 my $method = $get_method{$self->{'pname'}};
70 return $self->{'object'}->$method;
71 }
72  
73 my %set_method = (iter => (eval{Gtk2->VERSION(1.240);1}
74 ? 'set_active_iter'
75 # no $iter==undef support until Perl-Gtk2 1.240
76 : sub {
77 my ($combobox, $iter) = @_;
78 if ($iter) {
79 $combobox->set_active_iter($iter);
80 } else {
81 $combobox->set_active(-1);
82 }
83 }),
84 path => \&Gtk2::Ex::ComboBoxBits::set_active_path,
85 text => \&Gtk2::Ex::ComboBoxBits::set_active_text,
86 );
87 sub set_value {
88 my ($self, $value) = @_;
89 ### combobox_active set_value()
90 my $method = $set_method{$self->{'pname'}};
91 return $self->{'object'}->$method ($value);
92 }
93  
94 1;
95 __END__