Skip Menu |
 

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Mouse CPAN distribution.

Report information
The Basics
Id: 42992
Status: resolved
Priority: 0/
Queue: Mouse

People
Owner: Nobody in particular
Requestors: heikki.lehvaslaiho [...] gmail.com
Cc:
AdminCc:

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



Subject: Method modifiers affect all classes in the whole inheritance tree
Date: Tue, 3 Feb 2009 12:44:48 +0200
To: bug-Mouse [...] rt.cpan.org
From: Heikki Lehvaslaiho <heikki.lehvaslaiho [...] gmail.com>
Download (untitled) / with headers
text/plain 2.8k
This bug seems real enough for me. I took Randal Schwartz's Moose tutorial from http://www.stonehenge.com/merlyn/LinuxMag/col94.html and tried everything in Mouse. The 'after' (and 'before') method modifier is used in one of the subclasses (MouseA) of Animal, but their under Mouse they effect is visible in all subclasses (Horse, Sheep, MouseA,...). The same code under Moose works as expected. The code is below. -- -Heikki Heikki Lehvaslaiho - heikki lehvaslaiho gmail com -------------------------------------------------------------------------------------------------- #!/usr/bin/env perl # http://www.stonehenge.com/merlyn/LinuxMag/col94.html # The Mouse is Flying (part 1)' # Using Mouse, instead use feature ':5.10'; package Animal; use Mouse::Role; has 'name' => (is => 'rw'); sub speak { my $self = shift; print $self->name, " goes ", $self->sound, "\n"; } requires 'sound'; has 'color' => (is => 'rw', default => sub { shift->default_color }); requires 'default_color'; no Mouse::Role; 1; ## Cow.pm: package Cow; use Mouse; with 'Animal'; sub default_color { 'spotted' } sub sound { 'moooooo' } no Mouse; 1; ## Horse.pm: package Horse; use Mouse; with 'Animal'; sub default_color { 'brown' } sub sound { 'neigh' } no Mouse; 1; ## Sheep.pm: package Sheep; use Mouse; with 'Animal'; sub default_color { 'black' } sub sound { 'baaaah' } no Mouse; 1; package MouseA; use Mouse; with 'Animal'; sub default_color { 'white' } sub sound { 'squeak' } after 'speak' => sub { print "[but you can barely hear it!]\n"; }; before 'speak' => sub { print "[Ahem]\n"; }; no Mouse; 1; package Racer; use Mouse::Role; has $_ => (is => 'rw', default => 0) foreach qw(wins places shows losses); sub won { my $self = shift; $self->wins($self->wins + 1) } sub placed { my $self = shift; $self->places($self->places + 1) } sub showed { my $self = shift; $self->shows($self->shows + 1) } sub lost { my $self = shift; $self->losses($self->losses + 1) } sub standings { my $self = shift; join ", ", map { $self->$_ . " $_" } qw(wins places shows losses); } no Mouse::Role; 1; # To create the race horse, we just mix a horse with a racer: package RaceHorse; use Mouse; extends 'Horse'; with 'Racer'; no Mouse; 1; package main; #use Horse; my $talking = Horse->new(name => 'Mr. Ed'); say $talking->name; # prints Mr. Ed $talking->color("grey"); # sets the color $talking->speak; # says "Mr. Ed goes neigh" #use Sheep; my $baab = Sheep->new(color => 'white', name => 'Baab'); $baab->speak; # prints "Baab goes baaaah" #use MouseA my $mickey = MouseA->new(name => 'Mickey'); $mickey->speak; #use RaceHorse; my $s = RaceHorse->new(name => 'Seattle Slew'); $s->won; $s->won; $s->won; $s->placed; $s->lost; # run some races print $s->standings, "\n"; # 3 wins, 1 places, 0 shows, 1 losses --------------------------------------------------------------------------------------------------
Download (untitled) / with headers
text/plain 374b
Hi Heikki, Am I right in saying this is the correct output? Mr. Ed [Ahem] Mr. Ed goes neigh [but you can barely hear it!] [Ahem] Baab goes baaaah [but you can barely hear it!] [Ahem] Mickey goes squeak [but you can barely hear it!] 3 wins, 1 places, 0 shows, 1 losses My guess is that this is a bug caused by Data::Util. I'm forwarding this to that queue. Thanks, Shawn
Download (untitled) / with headers
text/plain 183b
I've moved this to the Class::Method::Modifiers::Fast queue. If I'm wrong please reply to this ticket so it'll pop back open. https://rt.cpan.org/Ticket/Display.html?id=43167 Shawn
Subject: Re: [rt.cpan.org #42992] Method modifiers affect all classes in the whole inheritance tree
Date: Tue, 10 Feb 2009 07:32:42 +0200
To: bug-Mouse [...] rt.cpan.org
From: Heikki Lehvaslaiho <heikki.lehvaslaiho [...] gmail.com>
Download (untitled) / with headers
text/plain 578b
Yes. That is the output. Cheers, -Heikki 2009/2/10 Shawn M Moore via RT <bug-Mouse@rt.cpan.org>: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=42992 > > > Hi Heikki, > > Am I right in saying this is the correct output? > > Mr. Ed > [Ahem] > Mr. Ed goes neigh > [but you can barely hear it!] > [Ahem] > Baab goes baaaah > [but you can barely hear it!] > [Ahem] > Mickey goes squeak > [but you can barely hear it!] > 3 wins, 1 places, 0 shows, 1 losses > > My guess is that this is a bug caused by Data::Util. I'm forwarding > this to that queue. > > Thanks, > Shawn >
Download (untitled) / with headers
text/plain 184b
Hi, Mouse maintainers. I think there is a problem in Mouse::Meta::Role; copying type-globs is problematic. Use CODE references instead. Regards, -- Goro Fuji (gfx) GFUJI at CPAN.org
Index: lib/Mouse/Meta/Role.pm =================================================================== --- lib/Mouse/Meta/Role.pm (revision 7618) +++ lib/Mouse/Meta/Role.pm (working copy) @@ -91,12 +91,12 @@ # XXX what's Moose's behavior? #next; } else { - *{"${classname}::${name}"} = *{"${selfname}::${name}"}; + *{"${classname}::${name}"} = \&{"${selfname}::${name}"}; } if ($args{alias} && $args{alias}->{$name}) { my $dstname = $args{alias}->{$name}; unless ($classname->can($dstname)) { - *{"${classname}::${dstname}"} = *{"${selfname}::${name}"}; + *{"${classname}::${dstname}"} = \&{"${selfname}::${name}"}; } } }
applied gfx++'s patch in reop, and test passed. e82cf08d6ab36c4269c82cb2e066defee22a26d8


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.