File Coverage

blib/lib/Gtk2/Ex/ContainerBits.pm
Criterion Covered Total %
statement 12 21 57.1
branch 0 4 0.0
condition n/a
subroutine 4 6 66.6
pod 2 2 100.0
total 18 33 54.5


line stmt bran cond sub pod time code
1             # Copyright 2010, 2011, 2012 Kevin Ryde
2              
3             # This file is part of Gtk2-Ex-WidgetBits.
4             #
5             # Gtk2-Ex-WidgetBits 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             # Gtk2-Ex-WidgetBits 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 Gtk2-Ex-WidgetBits. If not, see .
17              
18              
19             package Gtk2::Ex::ContainerBits;
20 1     1   939 use 5.008;
  1         3  
  1         58  
21 1     1   6 use strict;
  1         3  
  1         35  
22 1     1   6 use warnings;
  1         2  
  1         120  
23              
24 1     1   7 use Exporter;
  1         2  
  1         251  
25             our @ISA = ('Exporter');
26             our @EXPORT_OK = qw(remove_all
27             remove_widgets);
28              
29             our $VERSION = 48;
30              
31             sub remove_all {
32 0     0 1   my ($container) = @_;
33 0           push @_, $container->get_children;
34 0           goto &remove_widgets;
35             }
36              
37             # Shifting off each $child arg lets each get garbage collected immediately
38             # if nothing else refers to them. Probably not very important, and not a
39             # documented feature yet, but it means the widget is destroyed immediately
40             # after remove if not referred to elsewhere, which is probably what would be
41             # hoped for from remove_all().
42             #
43             sub remove_widgets {
44 0     0 1   my $container = shift;
45 0           while (@_) {
46 0           my $child = shift;
47 0 0         if (my $parent = $child->get_parent) {
48 0 0         if ($parent == $container) {
49 0           $container->remove ($child);
50             }
51             }
52             }
53             }
54              
55             1;
56             __END__