in reply to Object::MultiType - Perl Objects as Hash, Array & Scalar in the same time!

It turns out that when you dumped Symbol::genref you picked up exactly the bug I was attempting to avoid. You must delete the hash entry from the symbol table you just referenced. Do that and your code would look identical to Symbol::genref.

bart noticed that genref() (or the equivalent code (yours)) is actually very slow. PodMaster egged me on and I ended up creating Lexical::Typeglob::lexglob which is really just like Symbol::genref except it really avoids mucking with the symbol table. Its also four times faster than Symbol::genref which is nice. For the moment it can be downloaded from my personal site at http://www.greentechnologist.org/downloads/perl/Lexical-Typeglob-0.01.tar.gz and I'm considering publishing it on CPAN. I can't do that just yet because its missing documentation and a better test suite.

Replies are listed 'Best First'.
Re: Re: Object::MultiType - Perl Objects as Hash, Array & Scalar in the same time!
by gmpassos (Priest) on May 12, 2003 at 09:59 UTC
    Many thanks for all the work to test GLOB through Symbol. But now I'm fully avoiding GLOB and Symbol::.

    I have created a Saver object inside Object::MultiType::Saver, where this object stay inside the MultiType object, and now there is no need of GLOB or any extra thing.

    Thanks (to you and PodMaster) for the previous advices to avoid GLOB! ;-P

    Graciliano M. P.
    "The creativity is the expression of the liberty".

      As I recall, you can't handle globs this way and expect to get unique ones. As I recall localizing a symbol table entry and returning a reference will cause multiple uses to merge into a single shared instance. You still need to use gemsym() or my lexglob() for handling that $this->{g} instance.

      sub new { my $class = shift ; local(*NULL); my $this = { s => \'' , a => [] , h => [] , c => sub{} , g => \*NULL , } ; bless($this,$class); return( $this ) ; }
        The *NULL is not a GLOB to be used by the user! It's just here to avoid erros!

        If the user want a glob it need to paste it:

        my $obj = Object::MultiType->new(glob => \*MYGLOB) ;
        Will add some note in the POD! ;-P

        Graciliano M. P.
        "The creativity is the expression of the liberty".