blib/lib/Gtk3/Helper.pm

filter: Statementstmt 77.7% 7 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 83.3% 10 / 12 CC 1 SCAR 0.9
CC
1
Cov
78%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
↑ Summary
1 #
2 # $Id$
3 #
4  
5 package Gtk3::Helper;
6  
7 our $VERSION = '0.06';
8  
9 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 0 ▶use Glib;
Subroutine BEGIN: called CC=1 SCAR=2.6
13  
14 sub add_watch {
15 shift; # lose the class
16 my ($fd, $cond, $callback, $data) = @_;
17  
18 # map 'in' and 'out' to GIO enums
19 $cond = $cond eq 'in' ? 'G_IO_IN' :
20 $cond eq 'out' ? 'G_IO_OUT' :
21 croak "Invalid condition flag. Expecting: 'in' / 'out'";
22  
23 # In Gtk 1.x the callback was called also for the eof() / pipe close
24 # events, but Gtk 2.x doesn't. We need to connect to the G_IO_HUP
25 # event also to get this convenient behaviour again.
26  
27 my $tag = {
28 io_id => Glib::IO->add_watch ($fd, $cond, $callback, $data),
29 hup_id => Glib::IO->add_watch ($fd, 'G_IO_HUP', $callback, $data),
30 };
31  
32 return $tag;
33 }
34  
35 sub remove_watch {
36 shift; # lose the class
37 my ($tag) = @_;
38  
39 my $rc_io = Glib::Source->remove ($tag->{io_id});
40 my $rc_hup = Glib::Source->remove ($tag->{hup_id});
41
42 return ($rc_io && $rc_hup);
43 }
44  
45 1;
46  
47 __END__
↑ Summary