> From: Jonathan Scott Duff [mailto:[EMAIL PROTECTED] > On Mon, Dec 01, 2003 at 10:42:09AM -0500, Hodges, Paul wrote: > > > > module IHL::Roles; > > @ISA = 'Exporter'; > > @EXPORT_OK = qw/ fatal verbose allow setvals /; > > > > our role fatal is property { > > has $.fatal is rw; > > } > > > > our role verbose is property { > > has $.verbose is rw; > > } > > > > sub allow { > > .... # I'd want to make this one too complex to actually do it here > > } > > > > sub import { > > allow @_[1...]; > > } > > > > > sub setvals ($o, [EMAIL PROTECTED]) { > > "\$o.$_ = true".eval for @t; # surely there's a better way to do this? > > } > > Trying to keep up here ... but couldn't you do something like this? > > sub setvals ($o, [EMAIL PROTECTED]) { > $o but= $_(true); > } > > er, wouldn't you *have* to do something like that. If the object in > $o hasn't the property "foo", then C<$o.foo = true;> would be an > error, so you're trying to do 2 things: 1) give the object a property > and 2) assign a value to that property.
A) You're absolutely right. I goofed. :) B) What exactly does $_(true) mean in "$o but= $_(true);"? I assume you're setting the the value, so I think I understand it, but how about sub setvals ($o, [EMAIL PROTECTED]) { $o but= $_; $o.$_ = true; } Though I'm still "iffy" about that $o.$_ business..... I think $_(true) is better. I'm just fumbling for perspective. > I think you're trying to do too much in the above code. lol -- always. :) > If you just have a common set of roles that you want to use across objects, > you could do this: > > module MyRoles; > use Exporter; > @EXPORT_OK = <<verbose fatal>>; > > our property verbose is true; > our property fatal is true; > our property notexported; > our property *trulyglobal; > > then in other code: > > use MyRoles; > use SomeFancyStuff; > my $o = SomeFancyStuff.new() but verbose; > $o but= MyRoles.notexported; > $o but= trulyglobal; > > Or am I missing something? Should have been use MyRoles <<verbose>>; for one, shouldn't it? :) Nice concise definitions. But I still would like to be able to write a role generator in the module, so that I can pass it a list of roles I want valid and have it set them all up, so that my program only has to say use MyRoles <<allow setvals>>; use Thingy; my $o = Thingy.new(); allow <<foo bar baz>>; setvals $o, <<foo baz>>; instead of use Thingy; my $o = Thingy.new(); our property foo is true; our property bar is true; our property baz is true; $o but= foo; $o but= baz; Don't get me wrong; there's nothing wrong with this code. I just foresee certain things that I do commonly enough that I want to factor them out into something tested and consistent. Likewise, working on the details of such an implementation is always what makes the underlying "stuff" start to make sense to me. :) One thing, though.... could I do this? >=o} my property (foo,bar,baz) ^is true; $thingy ^but= (foo,baz); I'm pretty sure that syntax is way wonky -- would "is" be a vectorizable operator? Does it even qualify as an operator at all? > > then write allow() to build roles for each value passed in, > > maybe taking an arg to say whether they should be truly global, > > or built in the caller's namespace.... > > Isn't that what my, our, Exporter, and the globalifying * are > all about? Probably, though I haven't seen anything yet about how the P6 version of the Exporter is going to handle things like specifying exportation of my() vars &co. ***** "The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential, proprietary, and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers." 113