On Sunday, May 12, 2002, at 02:18  PM, Miko O'Sullivan wrote:

>> While thinking Eiffel-ish thoughts the other day, I began to wonder if
>> Perl6's classes could go beyond the simple private/public/protected
>> scheme by optionally allowing for a property or method to only be
>> accessed by a certain set of classes.
>
> Many times when I've used OO languages I've wished for something like 
> this.
> What I've often wanted would be standard method that is called before 
> every
> subroutine call. If that method returns false then the method that was
> called is not called.

I think maybe what you're looking for is another Eiffel/Sather-ism.  I 
know Eiffel at least has both pre and post-conditions that look 
something like this(it's been a while, so if this isn't quite right):

class
        ACCOUNT
creation
        make_with_balance
feature { BANK }
        balance: INTEGER
        make_with_balance(initial_balance: INTEGER) is
                require
                        initial_balance >= 0
                do
                        balance := initial_balance
                ensure
                        balance >= 0
                end
end

I too have thought this might be useful in Perl6.  Perhaps...

class Account {
                my INT $balance;
                method new(INT $initial_balance //= 0) {
                        REQUIRE { $initial_balance >= 0; }
                        $.balance = $initial_balance;
                        ENSURE { $.balance >= 0; }
                }
}
                                

Reply via email to