Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Re: Re: Re: Class::InsideOut - yet another riff on inside out objects.

by John M. Dlugosz (Monsignor)
on Dec 20, 2002 at 00:39 UTC ( [id://221305]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Class::InsideOut - yet another riff on inside out objects.
in thread Class::InsideOut - yet another riff on inside out objects.

Direct access is slower: Dereferencing the hash ref is not a big deal. It's only taking a reference that's slow, for some reason.

Naming the object twice: good point, that's no better than putting the name in the attribute's text.

Not generating an accessor: how do you do it now? I suppose that if you write your own accessor method it will overwrite the generated one, but then you have to make sure it happens in that order, and you have to take pains to zap the ones you don't want.

I think the 5.x attribute mechanism should be extended to get the source name and ref, not just (sometimes) a glob. As is now, attributes are pretty pointless on lexicals because it doesn't provide a way to associate the attribute with the thing it's attached to!

—John

  • Comment on Re: Re: Re: Re: Class::InsideOut - yet another riff on inside out objects.

Replies are listed 'Best First'.
Re^5: Class::InsideOut - yet another riff on inside out objects.
by adrianh (Chancellor) on Dec 20, 2002 at 14:11 UTC
    Not generating an accessor: how do you do it now?

    I don't generate them by default. You have to ask explicitly for accessors by using Class::InsideOut::Accessor.

    I suppose that if you write your own accessor method it will overwrite the generated one, but then you have to make sure it happens in that order, and you have to take pains to zap the ones you don't want.

    You would also get nasty errors under strict/warnings due to redefining the sub.

    With the current source filter mechanism the "right" way of doing it would be to turn the filter off when you don't want to have any accessors, e.g.:

    package Foo; use base qw(Class::InsideOut); use Class::InsideOut::Accessor; # build accessors for Fields use %foo : Field; # foo method built automatically no Class::InsideOut::Accessor; # stop building accessors use %bar : Field; # no accessor sub built sub bar { whatever... };
    I think the 5.x attribute mechanism should be extended to get the source name and ref, not just (sometimes) a glob.

    This may be possible. I'm not certain whether the difference in visibility of lexicals between 5.6.1 and 5.8 is a bug or not... need to spend some time looking at the code ;-)

    <update>See Lexical pad / attribute confusion for more detail on what I find confusing.</update>

    As is now, attributes are pretty pointless on lexicals because it doesn't provide a way to associate the attribute with the thing it's attached to!

    I think that's an over statement. The vast majority of the time you are interested in applying an attribute to a bit of perl data, and don't give a fig for the variables name. This is the only time I've used attributes where this has been an issue.

      This may be possible. I'm not certain whether the difference in visibility of lexicals between 5.6.1 and 5.8 is a bug or not... need to spend some time looking at the code ;-)

      I just read in the perldelta,

      Attributes for my variables now handled at run-time. The my EXPR : ATTRS syntax now applies variable attributes at run-time. (Subroutine and our variables still get attributes applied at compile-time.) See attributes for additional details. In particular, however, this allows variable attributes to be useful for tie interfaces, which was a deficiency of earlier releases. Note that the new semantics doesn't work with the Attribute::Handlers module (as of version 0.76).
      I mean per-accessor: you want some (most) but not all. Or you want those for public things but not private things.
        That's something an attribute could very elegantly handle:
        my %Mode : Field(rw); # generate accessor + mutator my %Status : Field(ro); # generate only accessor my %Connection : Field; # generate nothing
        I'm also thinking it would be nice if one could also write my %Mode : Field(rw custom); which would not create an accessor, but would test for the existence of one and complain if it didn't find one. That way the code becomes self documenting. Maybe a do-nothing private attribute would be nice to that end as well.

        Makeshifts last the longest.

Re^5: Class::InsideOut - yet another riff on inside out objects.
by adrianh (Chancellor) on Jan 04, 2003 at 20:14 UTC
    think the 5.x attribute mechanism should be extended to get the source name and ref, not just (sometimes) a glob.

    I've just come across Attribute::Handlers::Prospective, yet another neat module from TheDamian, that allows you to do this. From the documentation:

    If a lexical variable is given an attribute, there is no symbol table to which it belongs, so the symbol table argument ($_[1]) is set to the string 'LEXICAL(name)', where name is the name of the lexical (including its sigil). Likewise, ascribing an attribute to an anonymous subroutine results in a symbol table argument of 'ANON'.

    Neat. Implemented with a source filter.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2024-04-19 21:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found