Dave,

Sorry for taking so long to thank you for your reply.  Thanks.  On further
t, it was a silly question, using a plain old method is obviously the
solution.

I do have follow-up questions, though.  Suppose I want to generate those
plain old methods dynamically.  Is there a simple, moose way to do this in
the BUILD subroutine.   On e way to accomplish this is to assign an
anonymous subroutine to a glob.  Like this:

package My::App;

use Moose;
has name => ( is => 'rw', isa=>'Str' );

sub BUILD {
        **__PACKAGE__::method = sub { print "hello world\n"; } ;*
}

package main;
my $app = My::App->new( { name => 'Moose' } );
$app->method;


But I don't want to do that.  I want to do it the Moose way.

I can hear you ask, but why would you want to do that?  Well suppose, I
create an object that wraps a query.  If I can iterate over the record set I
can replace the data slot with the new record and still named methods that
act as accessors to the record.  This beats the snot out of trying to
instanciate a row object for each record.

Thanks in Advance,

Chris





On Wed, Mar 12, 2008 at 2:41 PM, Dave Rolsky <[EMAIL PROTECTED]> wrote:

> On Wed, 12 Mar 2008, Christopher Brown wrote:
>
> > Despite the 'lazy' evaluation, it appears as if the attribute value is
> being
> > cached instead of being re-evaluated when the accessor is being called.
>
> Lazy just means "don't generate the attribute from the default sub until
> the _first_ time it is requested". It's still cached.
>
> If you want to return a different value each time then you just want a
> plain old method, not an attribute.
>
>
> -dave
>
> /*==========================
> VegGuide.Org
> Your guide to all that's veg
> ==========================*/
>

Reply via email to