Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Tie and Tie::Handle

by Anonymous Monk
on Jul 18, 2002 at 00:06 UTC ( [id://182655]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to make an which is basicaly a IO::Socket::INET object with a few extra methods. As far as I can tell I need to use somthing todo with tie, but I have been unable to find much information.

Idealy I would like to beable to create the object using a normal constructor like I normaly would and straight away beable to straight away use like a filehandle

http://www.engelschall.com/~sb/download/pkg/Tie-Handle-3.0.README

from the information at the above url I assumed that the following should work:

package Listen; require Tie::Handle; @ISA = qw(Tie::Handle); use strict; use warnings; use IO::Socket::INET; sub new { #constructor my $class = shift; my $self = {}; bless $self; $self->tie(new IO::Socket::INET(Listen => 1, LocalPort => 1863, Re +useAddr => 1)); return $self; } 1;
and then in the main packge:
use listen; my $test = new Listen;
However this doesnt seem to work. I have also tried various other things, to no avail.

Any advice would be greatly appriciated,

Alan

Replies are listed 'Best First'.
Re: Tie and Tie::Handle
by kschwab (Vicar) on Jul 18, 2002 at 03:30 UTC
    I am trying to make an which is basicaly a IO::Socket::INET object with a few extra methods.

    You could just inherit from IO::Socket::INET and add your additional methods and whatnot. A small example of adding a peerhostport() method follows.

    package MyObject; use IO::Socket::INET; @ISA = ("IO::Socket::INET"); sub peerhostport { my $self=shift; my $peerport=$self->peerport; my $peerhost=$self->peerhost; return "$peerhost:$peerport"; } 1; package main; my $foo=MyObject->new(PeerAddr => 'www.perlmonks.org', PeerPort => '80', Proto => 'tcp'); my $string=$foo->peerhostport(); print "string is [$string]\n";
    Good luck !
Re: Tie and Tie::Handle
by Russ (Deacon) on Jul 18, 2002 at 00:26 UTC
    Are you sure you have Tie::Handle version 3.0? What you get from CPAN is likely version 4. See the COMPATIBILITY section of the perldoc for Tie::Handle for more information.

    Russ
    Brainbench 'Most Valuable Professional' for Perl

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (7)
As of 2024-04-23 13:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found