App/Chart/Glib/Ex/SignalBlock.pm untested

filter: Statementstmt 0.0% 0 / 45 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 66 CC 4 SCAR 15.9
CC
4
Cov
0%
DESTROY
12.0
add
6.0
new
2.0
CRAP 4.9
1 # or add() take one object and multiple ids
2 # or new() accept signalids object too
3  
4  
5  
6 # Copyright 2008, 2009, 2010, 2011 Kevin Ryde
7  
8 # This file is part of Chart.
9 #
10 # Chart is free software; you can redistribute it and/or modify it under the
11 # terms of the GNU General Public License as published by the Free Software
12 # Foundation; either version 3, or (at your option) any later version.
13 #
14 # Chart is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 # details.
18 #
19 # You should have received a copy of the GNU General Public License along
20 # with Chart. If not, see <http://www.gnu.org/licenses/>.
21  
22 package App::Chart::Glib::Ex::SignalBlock;
23 use 5.008;
24 use strict;
25 use warnings;
26 use Carp;
27  
28 # uncomment this to run the ### lines
29 #use Smart::Comments;
30  
31 sub new {
32 my $class = shift;
33 my $self = bless [], $class;
34 $self->add (@_);
35 return $self;
36 }
37  
38 sub new_from_signalids {
39 my ($class, $ids) = @_;
40 return $class->new ($ids->object, $ids->ids);
41 }
42  
43 sub add {
44 my $self = shift;
45 ### SignalBlock on: "@pairs"
46 if ((@_ & 1) != 0) {
47 croak "SignalBlock expects even number of arguments for object,id pairs";
48 }
49 require Scalar::Util;
50 while (@_) {
51 my $object = shift @_;
52 my $id = shift @_;
53 $object->handler_block ($id);
54 push @$self, $object,$id;
55 Scalar::Util::weaken ($self->[-2]);
56 }
57 }
58  
59 sub add_signalids {
60 my $self = shift;
61 while (@_) {
62 my $signalids = shift;
63 my $object = $signalids->object;
64 foreach my $id ($signalids->ids) {
65 $self->add ($object, $id);
66 }
67 }
68 }
69  
70 sub DESTROY {
71 my ($self) = @_;
72 while (@$self) {
73 my $object = shift @$self;
74 my $id = shift @$self;
75 next if (! defined $object); # possible weakening
76  
77 # could have been disconnected altogether by the application
78 if ($object->signal_handler_is_connected ($id)) {
79 ### SignalBlock unblock: "$object" . "id=$id"
80 $object->handler_unblock ($id);
81 }
82 }
83 }
84  
85 1;
86 __END__