Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Introducing MooseX::hasn't

by tobyink (Canon)
on Apr 01, 2012 at 09:32 UTC ( [id://962868]=CUFP: print w/replies, xml ) Need Help??

NAME

MooseX::hasn't - syntactic sugar to complement "has"

SYNOPSIS

{ package Person; use Moose; has name => (is => "ro", writer => "_rename", required => 1); } { package AnonymousPerson; use Moose; use MooseX::hasn't; extends "Person"; hasn't name => (default => 'anon'); } my $dude = AnonymousPerson->new; say($dude->can('_rename') ? 'true' : 'false'); # false say($dude->name); # croaks

more at MooseX::hasn't

perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Replies are listed 'Best First'.
Re: Introducing MooseX::hasn't
by Arunbear (Prior) on Apr 02, 2012 at 17:25 UTC
    The link you posted doesn't work.
    extends "Person"; hasn't name => (default => 'anon');
    that reads like a contradiction. If it doesn't support the same operations as Person then in what sense does it extend Person? Or is this meant to be an Acme type module?

      The link you posted doesn't work.

      Thanks, fixed.

      If it doesn't support the same operations as Person then in what sense does it extend Person?

      See "Doesn't this break polymorphism?" in the FAQ.

      Or is this meant to be an Acme type module?

      Initially, yes, hence the release date. But I can see potential uses for it.

      perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
        It breaks the inheritance contract, not polymorphism per se (I think you've got the two concepts confused). Polymorphism doesn't depend on inheritance, e.g. Roles enable polymorphism without inheritance.
Re: Introducing MooseX::hasn't
by Anonymous Monk on Apr 01, 2012 at 17:52 UTC
    I thought I read somewhere that the ' separator has been deprecated/depreciated

      It hasn't been deprecated yet (or at least, I don't get any warnings about it in 5.14.2, and there's no mention of its deprecation in perl5160delta), but it certainly seems a candidate for deprecation.

      The module doesn't rely on the apostrophe though. If you happen to find yourself on Perl 5.18 or whatever, and can't use apostrophe, then just use hasn::t and everything will be good.

      perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

        The module doesn't rely on the apostrophe though.

        Well, I think it does.  MooseX::hasn::t is much weaker than  MooseX::hasn't or even  MooseX::hasnot which is what you should have named this thing if you weren't trying to be c''l

        Cool, I guess replacing os with 's doesn't always work

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://962868]
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2024-04-23 15:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found