Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

dash2's scratchpad

by dash2 (Hermit)
on Jun 04, 2004 at 18:05 UTC ( #361054=scratchpad: print w/replies, xml ) Need Help??

sub bless { my ($object, $class) = @_; my $ref; $ref = CORE::ref $object if CORE::ref ($object) =~ /^(ARRAY|CODE|SCALAR|HASH|REF|GLOB|LVALUE)$/; unless ($ref) { if (UNIVERSAL::isa($object, 'HASH')) { $ref = 'HASH'; } elsif (UNIVERSAL::isa($object, 'ARRAY')) { $ref = 'ARRAY'; } elsif (UNIVERSAL::isa($object, 'SCALAR')) { $ref = 'SCALAR'; } } CORE::bless($object, $class); my ($proxy, %proxy, @proxy); my $methprox; if ($ref eq 'HASH') { tie %proxy, 'Class::Privacy::Proxy', $object; $methprox = CORE::bless (\%proxy, 'Class::Privacy::MethodProxy'); } elsif ($ref eq 'ARRAY') { tie @proxy, 'Class::Privacy::Proxy', $object; $methprox = CORE::bless (\@proxy, 'Class::Privacy::MethodProxy'); } elsif ($ref eq 'SCALAR') { tie $proxy, 'Class::Privacy::Proxy', $object; $methprox = CORE::bless (\$proxy, 'Class::Privacy::MethodProxy'); } else { croak "Class::Privacy can't create tied proxy for object $obje +ct"; } # create a new proxy object with $object hidden behind it # the proxy object is tied, and # handles data accesses of every sort (scalar, # hash, array). The reference to it is blessed # and handles methods. This gets round the Perl # "dereferencing bypasses tying" bug. Dereferencing # will always go to the tied proxy. $hiddens{$methprox} = $object; return $methprox; }

Perl Monks Approved HTML tags
Log In?

What's my password?
Create A New User
[LanX]: I have no idea how Mark scouted, giving that he lives in London ... but I think he mentioned his wife being Scottish
[marto]: ah, so this is payback :P
[LanX]: problem with booking venues is that you only know the number of participants a week in advance. ..
[marto]: I guess most cities have areas similar to this, I tend not to mind personally, but would not go out of my way to head down that way
[marto]: it'll probably be fine.
[marto]: LanX: I appreciate that, it's honestly a difficult thing, a fine balance
[marto]: I'm sure it'll be fun :)
[marto]: of course I can take you to some of the best/worst bars in Glasgow ;)

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (9)
As of 2017-12-14 15:52 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (396 votes). Check out past polls.