develooper Front page | perl.module-authors | Postings from November 2003

RE: Class::FakeAttributes -- Opinions Wanted

Thread Previous | Thread Next
From:
Orton, Yves
Date:
November 3, 2003 08:32
Subject:
RE: Class::FakeAttributes -- Opinions Wanted
Message ID:
71B318898201D311845C0008C75DAD1C0896135E@defra1ex2
> I guess in the absence of Class::InsideOut, having
> Class::OutOfBandAttributes as a band-aid isn't a bad idea.
> (There's a lot of orders of magnitude less useful stuff out on
> CPAN..)

Primary problem with creating a Class::InsideOut is the problem of where the
hashes go.

If you dont mind using dynamics for them then you have no problem. If you
want them in lexicals then I would say theres not much room to manoever, and
in hind site implementing an inside out object/attribute is so easy (its
pretty small, heres what I use for good general coverage:)

  use Scalar::Util qw(refaddr);

  {  
   my %attrib;
   sub inside_out {
	my $s=shift;
      if (@_) {
          $attrib{refaddr($s)}=shift;
          return $s;
      } else {
          return $attrib{refaddr($s)};
      }
   }
  }

The refaddr is useful because it allows for $s to have stringification
overloaded.

Yves

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About