Skip Menu |

This queue is for tickets about the Tickit-Widgets CPAN distribution.

Report information
The Basics
Id: 122231
Status: open
Priority: 0/
Queue: Tickit-Widgets

People
Owner: Nobody in particular
Requestors: rmzgrimes [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: SingleChildWidget->remove should update $self->{child}
Date: Mon, 26 Jun 2017 03:59:31 -0500
To: bug-Tickit-Widgets [...] rt.cpan.org
From: Robert Grimes <rmzgrimes [...] gmail.com>
When you call `remove` on a SingleChildWidget subclass it should update its specialized storage for its single child, namely `$self->{child}`. `set_child` should also probably re-use the logic in ContainerWidget when you call `set_child` while it already has a child (set_parent, window->close, etc)
On Mon Jun 26 04:59:43 2017, rmzgrimes@gmail.com wrote: Show quoted text
> When you call `remove` on a SingleChildWidget subclass it should update its > specialized storage for its single child, namely `$self->{child}`.
See attached. -- Paul Evans
Subject: rt122231.patch
=== modified file 'lib/Tickit/SingleChildWidget.pm' --- lib/Tickit/SingleChildWidget.pm 2015-03-27 19:17:14 +0000 +++ lib/Tickit/SingleChildWidget.pm 2017-06-26 10:46:41 +0000 @@ -1,7 +1,7 @@ # You may distribute under the terms of either the GNU General Public License # or the Artistic License (the same terms as Perl itself) # -# (C) Paul Evans, 2011-2013 -- leonerd@leonerd.org.uk +# (C) Paul Evans, 2011-2017 -- leonerd@leonerd.org.uk package Tickit::SingleChildWidget; @@ -108,6 +108,14 @@ $self->set_child( $_[0] ); } +sub remove +{ + my $self = shift; + my ( $child ) = @_; + croak "Cannot remove this child" if !$self->child or $self->child != $child; + $self->set_child( undef ); +} + =head1 AUTHOR Paul Evans <leonerd@leonerd.org.uk> === modified file 't/30box.t' --- t/30box.t 2017-06-26 10:41:26 +0000 +++ t/30box.t 2017-06-26 10:46:41 +0000 @@ -101,6 +101,10 @@ $widget->add( $child ); is( ( $widget->children )[0], $child, '$widget has one child after ->add' ); + + $widget->remove( $child ); + + ok( !$widget->children, '$widget->children empty finally' ); } done_testing;