Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Weird object happening

by stonecolddevin (Parson)
on Dec 04, 2003 at 04:44 UTC ( [id://312090]=perlquestion: print w/replies, xml ) Need Help??

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

Ok,
Here's the deal:
I have this object oriented site I am putting together, and I was wondering, why will doPage work when I use it like this:
grizzly::makeImage("img/brys_art.png", "30", "150", "masterpieces of a + genious"), q[&nbsp;&nbsp;&nbsp;<a href="photo?id=brys" title="bri +lliant">prity pikchurs</a> ] )

But not when I use it like this:
$nub->makeImage("img/brys_art.png", "30", "150", "masterpieces of a ge +nious"), q[&nbsp;&nbsp;&nbsp;<a href="photo?id=brys" title="bri +lliant">prity pikchurs</a> ] )
??
Any help is appreciated.
And if you're feeling lucky... come and take me home And if you feel loved If you feel lucky, if you feel loved If you feel lucky, if you feel loved You've crossed the walls - Excelled Further along through their hell All for my heart, I watch you kill You always have, you always will Now spread your wings and sail out to me....

update (broquaint): moved signature <div>

Replies are listed 'Best First'.
Re: Weird object happening
by cees (Curate) on Dec 04, 2003 at 05:18 UTC

    The 'makeImage' subroutine is acting like a function, and not a method.

    I find it easiest to understand the difference between a function and a method by looking at it in the way that perl actually handles them.

    # function call grizzly::makeImage(); # class method call grizzly->makeImage(); # Which perl translates to grizzly::makeImage('grizzly'); # object method call $nub->makeImage(); # which perl translates to grizzly::makeImage($nub);

    So unless 'makeImage' is expecting the classname or the object itself as the first parameter, it will only work as a function. I would recommend that you read the perltoot docs that come with perl. It will give you much better insight into how objects work in perl that I can in this post.

Re: Weird object happening
by blokhead (Monsignor) on Dec 04, 2003 at 05:06 UTC
    $obj->method("foo", "bar") gets translated (more or less) to SomePkg::method($obj, "foo", "bar") -- the object is passed into method as $_[0]. Your code for makeImage should expect the object as the first argument if you plan to use it as a method.

    If the function works as you desire right now, you probably don't need it to be OO, as it doesn't get passed the object anyway.

    blokhead

Re: Weird object happening
by !1 (Hermit) on Dec 04, 2003 at 05:09 UTC

    Umm. grizzly? However:

    $nub->makeImage("img/brys_art.png", "30", "150", "masterpieces of a ge +nious");

    is equivalent to

    *{"${\ref($nub)}::makeImage"}{CODE}->($nub,"img/brys_art.png", "30", " +150", "masterpieces of a genious");

    In other words, the second version has one too many parameters. Probably.

      Girzzly is my own pm, sry about the miscommunication.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (2)
As of 2024-04-26 00:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found