Re: Selective exporting of properties/methods
On Wednesday, May 15, 2002, at 10:17 AM, Aaron Sherman wrote: > On Sat, 2002-05-11 at 13:58, Chris Dutton wrote: > >> method world is public_to(Bar) { > > Might as well make that: > > method world is private(Bar) > > I tend to take any opportunity to recycle syntax, plus keywords with > underscores give me gas. ;) I had considered "is public(Bar)", but this works too.
Re: Selective exporting of properties/methods
On Sat, 2002-05-11 at 13:58, Chris Dutton wrote: > method world is public_to(Bar) { Might as well make that: method world is private(Bar) I tend to take any opportunity to recycle syntax, plus keywords with underscores give me gas. ;)
RE: Selective exporting of properties/methods
Miko O'Sullivan writes: >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. What you're describing is Aspect-Oriented Programming (I think). Take a look around CPAN for Aspect.pm and Hook::LexWrap. [says Mark who has never used AOP but only read about it in "Software Development"...] === Mark Leighton Fisher[EMAIL PROTECTED] Thomson multimedia, Inc.Indianapolis IN "Display some adaptability." -- Doug Shaftoe, _Cryptonomicon_
Re: PRE-POST methods [Was: Selective exporting of properties/methods]
[EMAIL PROTECTED] writes: : ]- I can't remember but i think I read somewhere or it was discussed here (can't :remember), but I think it was mentioned that Perl6 will have PRE and POST method/sub :handlers probably specified as attribute, so that (syntax may be wrong): : : class XXX { : method blah is PRE {} : method blah {} : method blah is POST {} : } : : is ok.. not sure about the FALSE-condition that prohnobit the blah-method-call ? Might just be a PRE and POST block within the method blah. : One more thing I was wondering would it be possible to define a method/sub with :different signatures but with the same name ? ( i think yes, ?Class::Multimethods?! :was doing that aren't it ?) I'm intending to allow overloading to the extent that the type system supports it. I foresee that the main difficulty will be knowing the the types on the caller end, not on the definition end. : PS. One thing just pooped to me... is the "class { }" a block so that we can do all :block mumbo-jumbo with it :") Well, sure, but it probably only executes inline with the surrounding code, just as any module initialization code does in Perl 5. I don't think it's a BEGIN variant. Larry
PRE-POST methods [Was: Selective exporting of properties/methods]
]- I can't remember but i think I read somewhere or it was discussed here (can't ]remember), but I think it was mentioned that Perl6 will have PRE and POST method/sub ]handlers probably specified as attribute, so that (syntax may be wrong): class XXX { method blah is PRE {} method blah {} method blah is POST {} } is ok.. not sure about the FALSE-condition that prohnobit the blah-method-call ? One more thing I was wondering would it be possible to define a method/sub with different signatures but with the same name ? ( i think yes, ?Class::Multimethods?! was doing that aren't it ?) raptor PS. One thing just pooped to me... is the "class { }" a block so that we can do all block mumbo-jumbo with it :") |> 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; } | } |} | |
Re: Selective exporting of properties/methods
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; } } }
Re: Selective exporting of properties/methods
> 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. A standard set of security information is passed in. That could get kind of expensive so the security method is only called if the class is specifically set to use it. Something like this: class Foo::Bar { use Class::Security::Method 'checker'; sub checker (%meta) { if (some_security_check()) {return 1} return 0; } } -Miko
Selective exporting of properties/methods
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. For instance(as I understand Perl6 syntax): class Foo { method hello is public { return "hello"; } method world is public_to(Bar) { # is only public to objects of class Bar return "world"; } } class Bar { method say_hello { # this works fine print Foo.new.hello, "\n"; } method say_world { # as does this print Foo.new.world, "\n"; } } class Baz { method say_world { # generates a run-time exception for trying to call a private method. print Foo.new.world, "\n"; } }