subclass versus new_with_foo
- From: Kevin Ryde <user42 zip com au>
- To: gtk-perl-list gnome org
- Subject: subclass versus new_with_foo
- Date: Tue, 24 Aug 2010 10:25:35 +1000
I noticed various class methods like Gtk2::TextView->new_with_buffer()
ignore their class name arg, so if you call from a subclass
MyTextView->new_with_buffer() you only get a base Gtk2::TextView.
Sample code below.
Is it feasible to have some of those new_with_foo() methods follow the
class name? An xs equivalent of maybe
# sub new_with_buffer {
# my ($class, $textbuf) = @_;
# return Glib::Object::new ($class, buffer => $textbuf);
# }
along the lines of the commented out
new_with_buffer() below maybe.
Many are simple shorthands for setting properties at create, or create
followed by $obj->set_foo. Perhaps any complicated ones could be
quietly ignored.
Following the class name would be good for Perl level subclassing.
I suppose the alternative is each subclass to think about what it needs
or wants, perhaps with some multi-inheritance mix-ins to offer likely
forms for a new_with_buffer() etc.
use strict;
use warnings;
{
package MyTextView;
use Gtk2;
use Glib::Object::Subclass 'Gtk2::TextView';
}
{ my $tv = MyTextView->new;
print "MyTextView new() gives: ",ref($tv),"\n"; }
{ my $tv = MyTextView->new_with_buffer (Gtk2::TextBuffer->new);
print "MyTextView new_with_buffer() gives: ",ref($tv),"\n";
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]