Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Introducing MooseX::hasn't

by tobyink (Abbot)
on Apr 01, 2012 at 09:32 UTC ( #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'

Comment on Introducing MooseX::hasn't
Download Code
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

Re: Introducing MooseX::hasn't
by Arunbear (Parson) 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.

Log In?
Username:
Password:

What's my password?
Create A New User
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? | Other CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2014-07-29 03:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (211 votes), past polls