File Coverage

blib/lib/Glib/Ex/SourceIds.pm
Criterion Covered Total %
statement 10 12 83.3
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 14 16 87.5


line stmt bran cond sub pod time code
1             # Copyright 2008, 2009, 2010, 2011, 2012, 2014 Kevin Ryde
2              
3             # This file is part of Glib-Ex-ObjectBits.
4             #
5             # Glib-Ex-ObjectBits is free software; you can redistribute it and/or modify
6             # it under the terms of the GNU General Public License as published by the
7             # Free Software Foundation; either version 3, or (at your option) any later
8             # version.
9             #
10             # Glib-Ex-ObjectBits is distributed in the hope that it will be useful, but
11             # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12             # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13             # for more details.
14             #
15             # You should have received a copy of the GNU General Public License along
16             # with Glib-Ex-ObjectBits. If not, see .
17              
18             package Glib::Ex::SourceIds;
19 1     1   566 use 5.008;
  1         2  
  1         30  
20 1     1   4 use strict;
  1         1  
  1         21  
21 1     1   4 use warnings;
  1         1  
  1         18  
22 1     1   1413 use Glib;
  0            
  0            
23              
24             our $VERSION = 16;
25              
26             sub new {
27             my ($class, @ids) = @_;
28             my $self = bless [], $class;
29             $self->add (@ids);
30             return $self;
31             }
32             sub add {
33             my ($self, @ids) = @_;
34             push @$self, @ids;
35             }
36              
37             sub DESTROY {
38             my ($self) = @_;
39             $self->remove;
40             }
41              
42             # g_source_remove() returns false if it didn't find the ID, so no need to
43             # check whether it's already removed (for instance by a false return from
44             # the handler function).
45             #
46             # Recent Glib has made incompatible changes to this so that
47             # g_source_remove() emits a g_log() error message on attempting to remove a
48             # non-existent ID.
49             #
50             sub remove {
51             my ($self) = @_;
52             while (my $id = pop @$self) {
53             Glib::Source->remove ($id);
54             }
55             }
56              
57             1;
58             __END__