Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: Reopen a class, add methods ?

by friedo (Prior)
on May 12, 2007 at 22:48 UTC ( #615126=note: print w/replies, xml ) Need Help??

in reply to Reopen a class, add methods ?

Either way works fine, though I prefer not to have multiple packages in one file. But that's just a matter of style.

However, it seems to me that defining a derived class would be a more sensible approach. If you don't want to make an actual module, you can define the class inline with your script.

The following is untested but demonstrates the idea.

#!/usr/bin/perl use strict; use Tk; use Tk::Label; use Tk::HList; package Rudif::Tk::HList; @Rudif::Tk::HList::ISA = ( 'Tk::HList' ); sub addrow { my ( $self, $row, $text ) = @_; $self->add($row); $self->itemCreate( $row, 0, -text => $text ); } sub updaterow { my ( $self, $row, $text ) = @_; $self->itemConfigure( $row, 0, -text => $text ); } package main; # your stuff here

Replies are listed 'Best First'.
Re^2: Reopen a class, add methods ?
by Rudif (Hermit) on May 13, 2007 at 15:21 UTC

    Originally I did experiment with inheritance, but I got into trouble with the Tk framework when I tried to instantiate my derived class. It seems that Tk classes are somehow different from typical perl classes.

    This is why I started looking for an alternative along the lines of 'reopen a class, add a method'.


Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://615126]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2023-03-21 07:38 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (59 votes). Check out past polls.