Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't use Method::Signatures::Modifiers with parameterized roles #70

Open
bitbugprime opened this issue Mar 9, 2013 · 1 comment
Open

Comments

@bitbugprime
Copy link

X.pm:

use MooseX::Declare;

role X (Str :$role) {
has "x_$role" => (
    is       => 'ro',
    isa      => 'Str',
    lazy     => 1,
    default  => sub { 'junk' },
    init_arg => undef,
);

method "print_x_$role" () {
    my $c = $role;
    print $c, "\n";
}
}

1;

main:

use MooseX::Declare;
use Method::Signatures::Modifiers;

class Z {
with 'X' => {role => 'test'};

method roller { '' }
}

my $a = Z->new;
$a->print_x_test;

If you comment out "use Method::Signatures::Modifiers" and run "perl main", it works fine. If you run as is, you get:

"my" variable $role masks earlier declaration in same scope at X.pm line 13.
"my" variable $c masks earlier declaration in same statement at X.pm line 14.
Type of arg 1 to X::method must be block or sub {} (not string) at X.pm line 12, near ""print_x_$role" ("
syntax error at X.pm line 12, near ""print_x_$role" ("

@schwern
Copy link
Contributor

schwern commented Mar 12, 2013

Turning on debugging...

METHOD_SIGNATURES_DEBUG=1 perl test.plx
DEBUG: attributes: 
DEBUG: inject:  BEGIN { Method::Signatures::Modifiers->inject_scope('') }; my $self = shift; Method::Signatures::Modifiers->too_many_args_error(0) if @_ > 0; 
DEBUG: before: sub 
DEBUG: linestr before:     method  { '' }

DEBUG: linestr after:     method  sub { BEGIN { Method::Signatures::Modifiers->inject_scope('') }; my $self = shift; Method::Signatures::Modifiers->too_many_args_error(0) if @_ > 0;  '' }

DEBUG: attributes: 
DEBUG: inject: my $self = shift; Method::Signatures::Modifiers->too_many_args_error(0) if @_ > 0; 
DEBUG: before: sub 
DEBUG: linestr before:     method "print_x_$role" () {

DEBUG: linestr after:     method "print_x_$role" () {

"my" variable $role masks earlier declaration in same scope at X.pm line 13.
"my" variable $c masks earlier declaration in same statement at X.pm line 14.
Type of arg 1 to X::method must be block or sub {} (not string) at X.pm line 12, near ""print_x_$role" ("
syntax error at X.pm line 12, near ""print_x_$role" ("
BEGIN not safe after errors--compilation aborted at X.pm line 15.
Compilation failed in require at test.plx line 5.

Somehow Method::Signatures::Modifiers is getting involved with the compilation of method "print_x_$role". Seems like that should be out of its scope!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants