Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Reopen a class, add methods ?

by friedo (Prior)
on May 12, 2007 at 22:48 UTC ( [id://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
    friedo,

    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'.

    Rudif

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-04-18 22:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found