stevan / p5-mop-redux

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

Top level classes issue #83

Closed stevan closed 11 years ago

stevan commented 11 years ago

So the issue is this:

package Foo;

class Foo {}

Actually creates class Foo::Foo, which may not be what is wanted. The proposed solution is to do:

package Foo;

class ::Foo {}

to indicate that we want a top-level class. This maps to how subs behave, so should be easy enough to understand.

Previously this was used as the solution:

package main;

class Foo {}

but this breaks down if you want to import functions that your class can use, such as:

package main;
use Path::Class qw[ file ];

class Foo {}

which then imported the file function into the main namespace, which is (more often then not) undesirable.

doy commented 11 years ago

Huh, I forgot that sub ::foo { } works. This is just a bug then.