Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Re: Re: Re: Re: Re: Re: Why breaking can() is acceptable

by simonm (Vicar)
on Apr 06, 2004 at 18:43 UTC ( #343073=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Re: Re: Re: Re: Why breaking can() is acceptable
in thread Why breaking can() is acceptable

On Class::FlyweightWrapper, the subroutine that you return is the one that is meant to be given the private object, not the public one. Since the caller isn't supposed to have the private object, that should be useless.

Wouldn't the following be sufficient?

package Class::FlyweightWrapper; ... sub can { my $self = $object{shift(@_)}; my ($method_name) = @_; my $sub = $self->can($method_name) or return; sub { $object{shift(@_)}->$method_name( @_ ) } }

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Re: Re: Re: Why breaking can() is acceptable
by tilly (Archbishop) on Apr 06, 2004 at 19:01 UTC
    No.

    You've not supported calling can() on the package. You've also not supported the correct behaviour of can() on methods that actually were defined directly in the PUBLIC class. Such as the constructor, or (now) can(). (A list to which which the user of the module could choose to add.)

    However you're right that someone who wanted to write the AUTOLOAD and then tried to add can() after the fact likely would implement just that and not notice the omissions. (Nor would the testing mantra help - you can't test cases that you didn't think of. And testing AUTOLOAD is harder than it looks because of how much behaviour even a short AUTOLOAD provides to write tests for.) Which illustrates by example my point that even when people try, they'll repeatedly get it wrong.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (1)
As of 2018-08-18 19:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Asked to put a square peg in a round hole, I would:









    Results (186 votes). Check out past polls.

    Notices?