Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: Re: Nested Classes

by InfiniteSilence (Curate)
on Mar 02, 2001 at 20:57 UTC ( #61819=note: print w/replies, xml ) Need Help??

in reply to Re: Nested Classes
in thread Nested Classes

Here's a slightly more verbose version of the same thing:
#!/usr/bin/perl -w use strict; package foo; sub new{ my $m = {}; bless $m; return $m;} package bar; sub new{ my $b = {}; bless $b; return $b;} sub corny { return 'sparky'; } package main; my $s = foo->new(); my $r = bar->new(); $s->{'spark'} = \&bar::corny; print $s->{'spark'}(); 1;
This essentially calls a method out of a different package. I added the class stuff as window dressing. If you are looking to call and actual method from an instantiated object, just call a function and use a reference to the object as a parameter (called delegation in certain circles) to call the function. Lastly, use inheritance. If these things don't help, I am not sure what you are attempting to accomplish.

Celebrate Intellectual Diversity

Replies are listed 'Best First'.
Re: Nested Classes
by Tyke (Pilgrim) on Mar 05, 2001 at 13:23 UTC
    The OP asked how to
    1. create an object,
    2. bless,
    3. and then bind subroutines to it (written within another objects method) as methods.

    That's what I tried to show. Sure it's better to define classes statically. But as I understood the OP, he wanted to do this on the fly

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (1)
As of 2023-03-25 04:34 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (62 votes). Check out past polls.