Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

I have a feeling I'm gonna be flamed for even writing this, but . . .man am I outta my depth.

Here's a module I wrote:

package OverloadObj use Want; sub import [ my $calling_package = caller; #{$calling_package . '::bless'} = \&constructor; } sub constructor { my $self; tie $self, 'OverloadObj', @_; return $self; } sub TIESCALAR { CORE::bless $_[1]; } sun FETCH { return $_[0] if want('REF'); $class = ref $_[0]; goto &{$class . 'OVERLOAD} (@_); } sub STORE { my $self = shift; untie $$self; } 1;

Now for a game of obfuscation! Can you guess what this prints?

package OverloadObj::Test; use OverloadObj; sub new { bless {}; } sub speak [ print 'Speak\n'; } sub OVERLOAD { return 'Bob'; } package main; $test = new OverloadObj::Test; $test->speak; print "$test";

Give up? On my Mandrake Linux 8.2 box, running 5.6.1, it print "Segmentation Fault.

First off let me say that I know the module doesn't qork, even if it didn't segfault. The want call is naive and I know that the STORE method isn't doing what I want it to do (and I'll explain that part in a bit). Frankly, I'm more than a little embarassed to show this bit of incomplete code. I've learned alot about Perl, but I don't get enough chances to code it - meaning I can fix other people's bugs faster and easier than I fix my own.

Disclaimer out of the way, a bit of background. The code pretty much came to me in a flash while thinking about something :Larry said in one of the Apocolypes, namely that every first class object would be able to define it's own numify and stringify overloadings. I saw lots of nifty uses for this technique, and decided I'd try to code up a modeule which did something similar in Perl 5 and make it a gift to the community and the Monastery in particular. After the pure Perl implementation proved unworkable and fragile (Although I came amazingly close, and it was pretty clever if I have to say so myself) I downloaded took it to me Linux box, ran make and had this thing ready to begin serious debugging about 20 minutes. The idea is to replace the object itself with a smart tie()d object that knows when to return the object itself and when to call $obj->OVERLOAD to allwo the object to provide numification/stringification. So, I wrote the quick test above for the preliminary debugging. Then segfault.

I'll be frank, I'm an idiot. I'm not a coder. I've been running Linux for a couple of weeks, and I can barely login to bash. I don't now what a segfault is. I've read Oh my God! Tie killed Perl! (everyone should) but I don't even now where to look to begin figuring out the source of the problem. Is it my bug? Perl's? Want? Linux? All of us?

/me bows his head in submission to authority and wisdom of other monks.

PS Sorry I'm not as funny as Petruchio. Maybe I'll think of an elaborate song and dance for whoever helps me fix the problem.


Light a man a fire, he's warm for a day. Catch a man on fire, and he's warm for the rest of his life. - Terry Pratchet

In reply to Perl Dead (Again). tie() Burns Corpse. Incommpotent Monk Assists Sacrilage. News At Eleven. by erikharrison

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others examining the Monastery: (4)
    As of 2021-04-14 19:53 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found