Re: How do I retrieve the 'type' of an object



On Sun, 2004-06-06 at 19:06, A. Pagaltzis wrote:
I'm not sure how much work would be involved for such an approach
with Gtk2-Perl though, since I've not subclassed/extended
anything yet, only used what was already there.

actually it's almost trivial you just need to be really careful that
whatever you name the method won't clash with some other (now or in the
future) method of Gtk2. package is the trick (not tested, but should be
about right):

my $btn = Gtk2::Button->new ('Click _Me');
my $label = Gtk2::Label->new ('Can't Click Me');

foreach ($btn, $label)
{
    $_->my_method;
}

package Gtk2::Button

sub my_method
{
    my $self = shift;
    print 'button text: '.$self->get_label ()."\n";
}

package Gtk2::Label

sub my_method
{
    my $self = shift;
    print 'label text: '.$self->get_label ()."\n";
}

-- 
-rm




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]