Subject: | Consider "return $self" in all set_* methods |
Currently all the widget ->set_* methods just return undef. Certain code styles become a lot more convenient if they instead return the object itself, so you can do things like
$vbox->add( Gtk3::Entry->new
->set_sensitive( 0 )
->set_alignment( ... )
);
Without it you have to do lots of temporary variables:
my $entry = Gtk3::Entry->new;
$entry->set_sensitive( 0 );
$entry->set_alignment( ... );
$vbox->add( $entry );
or maybe
$vbox->add( do {
my $entry = Gtk3::Entry->new;
...
$entry;
} );
If I have to do this a lot (as I often do around Gtk*) I usually make myself a helper:
my $set = sub {
my $self = shift;
my ( $attr, @args ) = @_;
my $method = "set_$attr";
$self->$method( @args );
return $self;
};
$vbox->add( Gtk3::Entry->new
->$set( sensitive => 0 )
->$set( alignment => ... )
);
but having that feature built-in would be handy indeed.
See also Object::Tap [https://metacpan.org/pod/Object::Tap]
--
Paul Evans