in reply to Inside-out classes structure
Your norm() function replaces Scalar::Util::refaddr() poorly. ident() is an alias of refaddr. These comments are mine, this code is TheDamian's.
Be well,sub refaddr($) { # prototypes are usually suspect, here a prototype # is reasonable because the usage of this routine is # very predictable. # Save the class; fail if we don't have an object my $pkg = ref($_[0]) or return undef; # rebless the object into a package that is supposed to # NOT to overload numeric coercion. This code is more # robust than yours but still fails if UNIVERSAL overloads # '0+'; to really be safe we'd need to # use CORE:: functions explicitly. # # I would have probably just used 'Scalar::Util' but # I'm the sort who goes looking for 'Scalar::Util::Fake', # you have to use something like "S::U::No_SuCh_PkG" # before I believe you mean it. bless $_[0], 'Scalar::Util::Fake'; # int() seems to have acquired a little magic when # applied to a reference. I hadn't noticed. my $i = int($_[0]); # restore the object to its package bless $_[0], $pkg; # return the decimal address $i; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Inside-out classes structure
by Zaxo (Archbishop) on Oct 02, 2005 at 06:59 UTC | |
|
Re^2: Inside-out classes structure
by xdg (Monsignor) on Oct 02, 2005 at 13:59 UTC | |
by rir (Vicar) on Oct 02, 2005 at 20:51 UTC | |
by xdg (Monsignor) on Oct 03, 2005 at 02:54 UTC |