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
=== 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;