Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Setting accessor with Object::Tiny

by 1nickt (Abbot)
on Aug 12, 2019 at 15:15 UTC ( #11104334=note: print w/replies, xml ) Need Help??


in reply to Setting accessor with Object::Tiny

Hi, I'd say it's too "lightweight" if you have to start hacking it :-)

I second haukex and recommend Moo for all OOP work, even for one-liners.

$ perl -wE 'package Foo { use Moo; has bar => (is => "rw", isa => sub +{ die "invalid" unless shift =~ /^[a-z]+$/ }) }; my $o = Foo->new(bar + => "baz"); $o->bar("qux"); say $o->bar; $o->bar(42)' qux isa check for "bar" failed: invalid at -e line 1.

Hope this helps!


The way forward always starts with a minimal test.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11104334]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2019-10-17 00:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?