Skip Menu |
 

This queue is for tickets about the Moo CPAN distribution.

Report information
The Basics
Id: 125659
Status: open
Priority: 0/
Queue: Moo

People
Owner: Nobody in particular
Requestors: perl [...] toby.ink
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: isa coderefs are able to alter the value they're passed
MIME-Version: 1.0
X-Mailer: MIME-tools 5.504 (Entity 5.504)
Content-Disposition: inline
X-RT-Interface: Web
Message-ID: <rt-4.0.18-26189-1529743968-505.0-0-0 [...] rt.cpan.org>
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Encrypt: 0
X-RT-Sign: 0
Content-Length: 171
Download (untitled) / with headers
text/plain 171b
use v5.14; use strict; use warnings; package Foo { use Moo; has fff => (is => 'ro', isa => sub { $_[0]++ }); } my $foo = Foo->new(fff => 41); say $foo->fff; # says 42
MIME-Version: 1.0
In-Reply-To: <rt-4.0.18-26189-1529743968-505.0-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.504 (Entity 5.504)
Content-Disposition: inline
X-RT-Interface: Web
References: <rt-4.0.18-26189-1529743968-505.0-0-0 [...] rt.cpan.org>
Content-Type: text/plain; charset="utf-8"
Message-ID: <rt-4.0.18-11945-1530002519-745.125659-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Encrypt: 0
X-RT-Sign: 0
Content-Length: 210
Download (untitled) / with headers
text/plain 210b
use v5.14; use strict; use warnings; package Foo { use Moo; use Sub::Quote qw( quote_sub ); has fff => (is => 'ro', isa => quote_sub q{ $_[0]++ }); } my $foo = Foo->new(fff => 41); say $foo->fff; # says 41
MIME-Version: 1.0
In-Reply-To: <rt-4.0.18-26189-1529743968-505.0-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.504 (Entity 5.504)
Content-Disposition: inline
X-RT-Interface: Web
References: <rt-4.0.18-26189-1529743968-505.0-0-0 [...] rt.cpan.org>
Content-Type: text/plain; charset="utf-8"
Message-ID: <rt-4.0.18-14121-1530002895-1169.125659-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Encrypt: 0
X-RT-Sign: 0
Content-Length: 229
Download (untitled) / with headers
text/plain 229b
use v5.14; use strict; use warnings; package Foo { use Moo; use Sub::Quote qw( quote_sub ); has fff => (is => 'ro', isa => quote_sub q{ my ($value) = @_; $value++ }); } my $foo = Foo->new(fff => 41); say $foo->fff; # says 42
MIME-Version: 1.0
In-Reply-To: <rt-4.0.18-26189-1529743968-505.0-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.504 (Entity 5.504)
Content-Disposition: inline
X-RT-Interface: Web
References: <rt-4.0.18-26189-1529743968-505.0-0-0 [...] rt.cpan.org>
Content-Type: text/plain; charset="utf-8"
Message-ID: <rt-4.0.18-11945-1530003166-27.125659-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Encrypt: 0
X-RT-Sign: 0
Content-Length: 345
Download (untitled) / with headers
text/plain 345b
Best solution might be just to document it. Something like: For efficiency, Moo will sometimes avoid copying a value before passing it to the isa check. This means the isa coderef can inadvertently modify the value that is used to construct the object. Do not rely on this behaviour as it is inconsistent and may change from version to version.
MIME-Version: 1.0
In-Reply-To: <rt-4.0.18-11945-1530003166-27.125659-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.504 (Entity 5.504)
Content-Disposition: inline
X-RT-Interface: Web
References: <rt-4.0.18-26189-1529743968-505.0-0-0 [...] rt.cpan.org> <rt-4.0.18-11945-1530003166-27.125659-0-0 [...] rt.cpan.org>
Content-Type: text/plain; charset="utf-8"
Message-ID: <rt-4.0.18-4905-1530009120-1913.125659-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Encrypt: 0
X-RT-Sign: 0
Content-Length: 692
Download (untitled) / with headers
text/plain 692b
On Tue Jun 26 04:52:46 2018, TOBYINK wrote: Show quoted text
> Best solution might be just to document it. Something like: > > For efficiency, Moo will sometimes avoid copying a value before > passing it to the isa check. This means the isa coderef can > inadvertently modify the value that is used to construct the object. > Do not rely on this behaviour as it is inconsistent and may change > from version to version.
I think that seems reasonable. It will always be possible to modify the value being checked in some cases (references) so I don't think there is a strong case for changing the current behavior. If someone does come up with a more concrete problem with this, it can always be revisited.
MIME-Version: 1.0
In-Reply-To: <rt-4.0.18-26189-1529743968-505.0-0-0 [...] rt.cpan.org>
X-Mailer: MIME-tools 5.504 (Entity 5.504)
Content-Disposition: inline
X-RT-Interface: Web
References: <rt-4.0.18-26189-1529743968-505.0-0-0 [...] rt.cpan.org>
Content-Type: text/plain; charset="utf-8"
Message-ID: <rt-4.0.18-23131-1530524476-907.125659-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Encrypt: 0
X-RT-Sign: 0
Content-Length: 458
Download (untitled) / with headers
text/plain 458b
For reference, this is Moose's behaviour: Inlined type constraints *can* alter the value. Non-inlined type constraints can't. (Or at least, I haven't been able to trick them into changing the value.) perl -E'package Foo { use Moose; use Moose::Util::TypeConstraints; subtype "NonNeg", as "Int", where { ++$_[0] > 0 }, inline_as { "++$_[1] > 0" }; has foo => (is => "ro", isa => "NonNeg"); __PACKAGE__->meta->make_immutable}; say Foo->new(foo => 41)->foo'
MIME-Version: 1.0
X-Spam-Status: No, score=-5.24 tagged_above=-99.9 required=10 tests=[AWL=-0.139, BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FROM_OUR_RT=-4, HTML_MESSAGE=0.001, MIME_BOUND_DIGITS_15=0.798] autolearn=ham
In-Reply-To: <rt-4.0.18-23131-1530524476-1910.125659-5-0 [...] rt.cpan.org>
X-Cpan.org: This message routed through the cpan.org mail forwarding service. Please use PAUSE pause.perl.org to configure your delivery settings.
X-Spam-Flag: NO
X-RT-Interface: API
References: <RT-Ticket-125659 [...] rt.cpan.org> <rt-4.0.18-26189-1529743968-505.125659-5-0 [...] rt.cpan.org> <rt-4.0.18-23131-1530524476-1910.125659-5-0 [...] rt.cpan.org>
X-Virus-Scanned: Debian amavisd-new at bestpractical.com
X-Received: by 2002:aca:2c02:: with SMTP id s2-v6mr8403579ois.82.1530550557416; Mon, 02 Jul 2018 09:55:57 -0700 (PDT)
Message-ID: <CAPJsHfDNFm-+uodMuZVtt-ropvLj89-MT9edhKZwVSVGJqH7SQ [...] mail.gmail.com>
Content-Type: multipart/alternative; boundary="0000000000004938460570071219"
X-Spam-Score: -5.24
X-Google-SMTP-Source: AAOMgpdMhJxcJedpbXwi5FFCzdA0UWeLljPPbMjZXO7T5TPxTbGtgF5xIgVEajRofo+kuUSQf5W9wcfZhP6poTwlJUU=
Authentication-Results: hipster.bestpractical.com (amavisd-new); dkim=pass header.i= [...] froods-org.20150623.gappssmtp.com
Received: from localhost (localhost [127.0.0.1]) by hipster.bestpractical.com (Postfix) with ESMTP id 2A1B4240344 for <cpan-bug+Moo [...] hipster.bestpractical.com>; Mon, 2 Jul 2018 12:56:06 -0400 (EDT)
Received: from hipster.bestpractical.com ([127.0.0.1]) by localhost (hipster.bestpractical.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id GYCuHf7ufeTO for <cpan-bug+Moo [...] hipster.bestpractical.com>; Mon, 2 Jul 2018 12:56:04 -0400 (EDT)
Received: from xx1.develooper.com (xx1.develooper.com [207.171.7.115]) by hipster.bestpractical.com (Postfix) with ESMTPS id DA9F3240341 for <bug-Moo [...] rt.cpan.org>; Mon, 2 Jul 2018 12:56:03 -0400 (EDT)
Received: from localhost (xx1.develooper.com [127.0.0.1]) by localhost (Postfix) with ESMTP id 80B9867011 for <bug-Moo [...] rt.cpan.org>; Mon, 2 Jul 2018 09:56:02 -0700 (PDT)
Received: from xx1.develooper.com (xx1.develooper.com [127.0.0.1]) by localhost (Postfix) with SMTP id 7BE7667010 for <bug-Moo [...] rt.cpan.org>; Mon, 2 Jul 2018 09:56:00 -0700 (PDT)
Received: from mail-oi0-f41.google.com (mail-oi0-f41.google.com [209.85.218.41]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by xx1.develooper.com (Postfix) with ESMTPS id 7BA4F6700E for <bug-Moo [...] rt.cpan.org>; Mon, 2 Jul 2018 09:55:58 -0700 (PDT)
Received: by mail-oi0-f41.google.com with SMTP id s198-v6so13783427oih.11 for <bug-Moo [...] rt.cpan.org>; Mon, 02 Jul 2018 09:55:58 -0700 (PDT)
Received: by 2002:a9d:208a:0:0:0:0:0 with HTTP; Mon, 2 Jul 2018 09:55:56 -0700 (PDT)
Delivered-To: cpan-bug+Moo [...] hipster.bestpractical.com
Subject: Re: [rt.cpan.org #125659] isa coderefs are able to alter the value they're passed
Return-Path: <karen [...] froods.org>
Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=froods-org.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=P4xscUUvMSpd7hgY2/W0AJcAQZHe2+eAcQCV0nr5QCE=; b=Pn853nqG0tHueQdr8bcwXvd40YzGXgA8RqgUVrOsBKQWyrEpuYbMfbOSD5olizntqi WbI6/7/F/ahJpqdkalZRr89MN65lvK3txHkmWMmZ5RsoQKApC95kDlw8COgWFHmPrG0x svyqt3xVAHW9xvqfWwuOEKhCMWN5I9yI7p8bnnaygimUFVoQM490LqCn0JNoOlfH+AQ4 h+FIwxlcSMnhVUx/pN+jxoWpdn6I4ortruXxNe3FLZPQ25O7eJcfrWXED9WYSkHpsJdB P52uJYuxnKbNTVs7kHZTXTFyRj/7Q8jg57CebdrJpUHw79kn9FZeMoUczXg2pvY6J7Op o9iw==
X-Original-To: cpan-bug+Moo [...] hipster.bestpractical.com
X-RT-Mail-Extension: moo
X-Google-Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=P4xscUUvMSpd7hgY2/W0AJcAQZHe2+eAcQCV0nr5QCE=; b=YN2FQK7oBtYoYbpGZQ6mv3NeLORRS5nBDpPPiZaeBRk4jUb0ufe4IXHdHUOpq5uzfY +yqJ+IRKpMqFZvrbr3l93wre7rzw7tBf/rTFwzLN8a5LW38ACAaBb07vqdhdqJI6cR0N qz4ON0mW9hXoey5KXxHTe8stQ6F536g8v524ocpMSRANEnspcP40w4QBm1MPR0QielZl rakFN17jv9Ytr8wbWUAuJClVOnGUqZ15PiLcmO3kfQI7Js2J7oYSteeyfGNyoJJqyY+S q9x/h67Zqnuqsg5ezT7Gozoi+P4ie0IiyL55AzvLI/p1nqx+Ifn1yNFGHTJ6iiHYOmbF NKFw==
Date: Mon, 2 Jul 2018 09:55:56 -0700
X-PMX-Spam: Gauge=IIIIIIII, Probability=8%, Report=' BODYTEXTH_SIZE_10000_LESS 0, BODYTEXTP_SIZE_3000_LESS 0, BODY_SIZE_2000_2999 0, BODY_SIZE_5000_LESS 0, BODY_SIZE_7000_LESS 0, DATE_TZ_NA 0, DKIM_SIGNATURE 0, IN_REP_TO 0, LEGITIMATE_SIGNS 0, MSG_THREAD 0, REFERENCES 0, SPF_NONE 0, URI_ENDS_IN_HTML 0, WEBMAIL_SOURCE 0, __ANY_URI 0, __BOUNCE_CHALLENGE_SUBJ 0, __BOUNCE_NDR_SUBJ_EXEMPT 0, __CP_URI_IN_BODY 0, __CT 0, __CTYPE_HAS_BOUNDARY 0, __CTYPE_MULTIPART 0, __CTYPE_MULTIPART_ALT 0, __DQ_NEG_HEUR 0, __DQ_NEG_IP 0, __FORWARDED_MSG 0, __FRAUD_MONEY_CURRENCY 0, __FRAUD_MONEY_CURRENCY_DOLLAR 0, __FUR_RDNS_GMAIL 0, __HAS_FROM 0, __HAS_HTML 0, __HAS_MSGID 0, __HELO_GMAIL 0, __HIGHBITS 0, __HTML_AHREF_TAG 0, __HTML_TAG_DIV 0, __HTTPS_URI 0, __IN_REP_TO 0, __MIME_HTML 0, __MIME_TEXT_H 0, __MIME_TEXT_H1 0, __MIME_TEXT_H2 0, __MIME_TEXT_P 0, __MIME_TEXT_P1 0, __MIME_TEXT_P2 0, __MIME_VERSION 0, __MULTIPLE_URI_TEXT 0, __PHISH_SPEAR_HTTP_RECEIVED 0, __RATWARE_SIGNATURE_3_N1 0, __RDNS_WEBMAIL 0, __REFERENCES 0, __SANE_MSGID 0, __SUBJ_ALPHA_END 0, __SUBJ_ALPHA_NEGATE 0, __SUBJ_REPLY 0, __TO_MALFORMED_2 0, __TO_NO_NAME 0, __URI_IN_BODY 0, __URI_NOT_IMG 0, __URI_NO_WWW 0, __URI_NS , __URI_WITHOUT_PATH 0, __URI_WITH_PATH 0, __YOUTUBE_RCVD 0, __zen.spamhaus.org_ERROR '
X-Spam-Level:
X-PMX-Version: 5.6.1.2065439, Antispam-Engine: 2.7.2.376379, Antispam-Data: 2018.4.8.232716
To: bug-Moo [...] rt.cpan.org
X-GM-Message-State: APt69E3fUN5Xz2LxzXDzss4LGNGAITVmadg/+xK4B6gbpIb5uFS24Toe YgXDDMtcVFu2IprVbED+071oXgX4Fg9rYpid92mUHg==
From: Karen Etheridge <karen [...] froods.org>
RT-Message-ID: <rt-4.0.18-12287-1530550568-1705.125659-0-0 [...] rt.cpan.org>
Content-Length: 0
content-type: text/plain; charset="utf-8"
X-RT-Original-Encoding: utf-8
Content-Length: 812
Download (untitled) / with headers
text/plain 812b
Especially since whether a type is inlined should be invisible to the user, I would argue this is unintentional in Moose, and we should fix it there as well. On Mon, Jul 2, 2018 at 2:41 AM, Toby Inkster via RT <bug-Moo@rt.cpan.org> wrote: Show quoted text
> Queue: Moo > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=125659 > > > For reference, this is Moose's behaviour: > > Inlined type constraints *can* alter the value. > > Non-inlined type constraints can't. (Or at least, I haven't been able to > trick them into changing the value.) > > > perl -E'package Foo { use Moose; use Moose::Util::TypeConstraints; subtype > "NonNeg", as "Int", where { ++$_[0] > 0 }, inline_as { "++$_[1] > 0" }; has > foo => (is => "ro", isa => "NonNeg"); __PACKAGE__->meta->make_immutable}; > say Foo->new(foo => 41)->foo' >
content-type: text/html; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 1423


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.