stevan / p5-mop-redux

A(nother) MOP for Perl 5
139 stars 36 forks source link

mop classes appear to be bleeding exports into main:: #155

Closed fgabolde closed 10 years ago

fgabolde commented 10 years ago

E.g.

#!perl

use strict;
use warnings;
use 5.010;
use Carp;

use Test::More;
use Test::Exception;

use mop;
class Foo {
    use Scalar::Util qw/reftype/;
}
no mop;

package Bar {
    use Scalar::Util qw/blessed/;
}

my $ref = [];
throws_ok(sub { reftype($ref) }, qr/Undefined subroutine &main::reftype/);
throws_ok(sub { blessed($ref) }, qr/Undefined subroutine &main::blessed/);

done_testing;

Fails with:

not ok 1 - threw Regexp ((?^:Undefined subroutine &main::reftype))
#   Failed test 'threw Regexp ((?^:Undefined subroutine &main::reftype))'
#   at mopmwo.pl line 22.
# expecting: Regexp ((?^:Undefined subroutine &main::reftype))
# found: normal exit
ok 2 - threw Regexp ((?^:Undefined subroutine &main::blessed))
1..2
# Looks like you failed 1 test of 2.

Adding namespace::clean after the reftype import makes the problem worse (my perl 5.18.1 segfaults, actually).

stevan commented 10 years ago

Yes, they are, however this is "intended" behavior. class blocks are not the same as package blocks, they are more like sub blocks.

stevan commented 10 years ago

In fact, class follows sub both in this regard as well as in naming. So package Bar { class Foo {} } created a class named Bar::Foo while package Bar { class Foo::Bar {} } creates a class named Foo::Bar, just as a sub would.

fgabolde commented 10 years ago

Ah, fair enough. My classes are no longer polluting the global namespace now!

The comparison to subs is really spot on, is this documented somewhere?

stevan commented 10 years ago

No, not yet. Documentation is part of New Years Resolution, along with spending more time on p5p.

On Dec 31, 2013, at 10:31 AM, Fabrice Gabolde notifications@github.com wrote:

Ah, fair enough. My classes are no longer polluting the global namespace now!

The comparison to subs is really spot on, is this documented somewhere?

— Reply to this email directly or view it on GitHub.