Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Mom CPAN distribution.

Report information
The Basics
Id:
134617
Status:
resolved
Priority:
Low/Low
Queue:

People
Owner:
Nobody in particular
Requestors:
0briang0 [...] gmail.com
Cc:
AdminCc:

BugTracker
Severity:
(no value)
Broken in:
(no value)
Fixed in:
(no value)



To: bug-Mom@rt.cpan.org
From: 0briang0@gmail.com
Date: Thu, 04 Mar 2021 09:05:20 -0500
Subject: :rwp is not working
Consider the following code use 5.010; package Abc { use Mom q{ attr :rwp }; # use Moo; # has attr => (is => 'rwp'); }; my $abc = Abc->new(attr=>'one'); say $abc->attr; # one $abc->attr('two'); say $abc->attr; # two say $abc->_set_attr('three'); # Can't locate object method "_set_attr" via package "Abc" I expect the statement C<$abc->attr('two');> to fail, as C<attr> is declared C<:rwp>. Instead, it has the new value assigned. If I comment out the C<use> line and uncomment the two following lines (ie switch from C<Mom> to C<Moo>), C<$abc->attr('two');> fails as I expected. $Mom::VERSION: 0.004 $Moo::VERSION: 2.004004
Fix was easier than anticipated:) The tokenising regex was trying to match C<:rw> before C<:rwp> so the fix was to just to swap the ordering. patch with test (also attached as file cos I don't know which you prefer): diff --git a/lib/Mom.pm b/lib/Mom.pm index c40fd63..f7981a7 100644 --- a/lib/Mom.pm +++ b/lib/Mom.pm @@ -15,7 +15,7 @@ use Regexp::Common; my $token_re = qr{(?: (?: [^0-9\W]\w* ) | \: (?: isa|enum|does|type|handles|with|extends|default|requires|builder|trigger|clearer ) $RE{balanced} - | \: (?: rw|ro|rwp|bare|private|lazy|required|clearer|builder|trigger|role|std|common|path ) + | \: (?: ro|rwp|rw|bare|private|lazy|required|clearer|builder|trigger|role|std|common|path ) )}x; sub import { diff --git a/t/90rt134617.t b/t/90rt134617.t new file mode 100644 index 0000000..72a179d --- /dev/null +++ b/t/90rt134617.t @@ -0,0 +1,41 @@ +=pod + +=encoding utf-8 + +=head1 PURPOSE + +Demonstrate that Mom ignores :rwp (RT134617) + +=head1 AUTHOR + +Brian Greenfield E<lt>briang at cpan dot orgE<gt>. + +=head1 COPYRIGHT AND LICENCE + +This software is copyright (c) 2020 by Toby Inkster. + +This is free software; you can redistribute it and/or modify it under +the same terms as the Perl 5 programming language system itself. + +=cut + + +use strict; +use warnings; +use Test::More; +use Test::Exception; + +{ + package Foo; + use Mom 'foo :rwp'; +} + +my $obj = Foo->new( foo => 1 ); + +is $obj->foo, 1, "can get a :rwp attribute"; + +throws_ok { + $obj->foo(2); +} qr/^Usage/, 'attempt to set :rwp attribute'; + +done_testing;
Subject: patch

Message body not shown because it is not plain text.

Thanks; fixed in 0.005


This service runs on Request Tracker, is sponsored by The Perl Foundation, and maintained by Best Practical Solutions.

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