CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
Custom accessors work in Moose but not in Moo

 



porton
Novice

Sep 8, 2016, 7:08 AM

Post #1 of 2 (3324 views)
Custom accessors work in Moose but not in Moo Can't Post

The following Perl code works with Moose but does not work (throws an exceptions) with Moo.


Code
#!/usr/bin/perl 

package X;
use Moo;

my $BusinessClass = "X";
my $Key = 'zz';

no strict 'refs';
*{"${BusinessClass}::access_$Key"} = sub { "Modified $Key" };
has $Key => ( is => 'rw',
required => 0,
accessor => { $Key => \&{"${BusinessClass}::access_$Key"} },
# predicate => { "has_$Key",\&{"${BusinessClass}::access2_$Key"} },
);

my $obj = X->new;
print $obj->zz, "\n";


My real-life problem is how to generate classes whose fields are accessed through custom accessors. With Moose it can be accomplished by code like the above. But how to do this with Moo?


(This post was edited by porton on Sep 8, 2016, 7:09 AM)


porton
Novice

Sep 8, 2016, 8:26 AM

Post #2 of 2 (3315 views)
Re: [porton] Custom accessors work in Moose but not in Moo [In reply to] Can't Post

Do you see what I need?

I want to make Moo accessors which use Perl closures (a different closure for each accessor).

How to do this?

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives