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

Re: RFC Magic::Attach

by adrianh (Chancellor)
on Jan 21, 2003 at 14:04 UTC ( [id://228680]=note: print w/replies, xml ) Need Help??


in reply to RFC Magic::Attach

Comments/suggestions:

  • I would name the subroutines attach and unattach rather than attach_var and unattach_var (they're attaching the reference not the variable.)
  • Maybe have the name default to the current package, rather than Magic::Attach? I'd lean towards making it compulsary.
  • This kind of thing:
    my $foo = attached($ref,'elements') || attach_var($ref,$something,'ele +ments')
    is likely to be common enough to encapsulate. Maybe:
    my $foo = attach_default($ref, $something, 'elements');
  • Data::Attach rather than Magic::Attach? I don't think Magic is an appropriate top-level namespace... Devel::Attach would be good too.

Can't really comment on the implementation - I don't know the internals well enough.

Replies are listed 'Best First'.
Re: Re: RFC Magic::Attach
by pdcawley (Hermit) on Jan 21, 2003 at 15:54 UTC
    Have we considered how nicely this would play with scalar attributes? One could imagine appropriate Attribute::Handlers hanging their data off arbitrary scalars. Then one could imagine:
    sub UNIVERSAL::property { require Magic::Attach; my $self = shift; my $property_name = shift; return Magic::Attached::attached($self, $property_name); } sub UNIVERSAL::but { require Magic::Attach; my $self = shift; my($property_name, $value) =@_; Magic::Attach::attach($self, $property_name, $value); }
    and the like.

    The fun begins when you start to try and implement Perl6ish tricks along the lines of return $value->but('true') or (possibly nicer) return $value :but('true'); . For this to work really well you would need have 'but' dispatch to appropriate handlers in some way (possibly through a registry system), but it's not beyond the wit of man...

    Can you tell I've been thinking along these lines for a while but have lacked the appropriate tuits?

Re: Re: RFC Magic::Attach
by IlyaM (Parson) on Jan 21, 2003 at 14:43 UTC
      It was actually "detach" at first though I changed it because attach/unattach had a better ying/yang to me than attach/detach. Suppose I could alias it.

      -Lee

      "To be civilized is to deny one's nature."

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-03-28 23:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found