Toby Inkster avatar Toby Inkster committed fe2e56c

retain flag

Comments (0)

Files changed (4)

lib/MooX/Struct.pm

 
 BEGIN {
 	$MooX::Struct::AUTHORITY = 'cpan:TOBYINK';
-	$MooX::Struct::VERSION   = '0.006';
+	$MooX::Struct::VERSION   = '0.007';
 }
 
 use Moo          1.000000;
 	require Term::ANSIColor;
 	my $self   = shift;
 	
-	my @values = map { scalar Data::Printer::p($_) } @$self;
+	my @values = map { scalar Data::Printer::p(\$_) } @$self;
 
 	if (grep /\n/, @values)
 	{
 	{
 		no warnings;
 		our $AUTHORITY = 'cpan:TOBYINK';
-		our $VERSION   = '0.006';
+		our $VERSION   = '0.007';
 	}
 	
 	sub _uniq { my %seen; grep { not $seen{$_}++ } @_ };
 				code   => $self->class_map->{ $subname },
 			};
 		}
+		
 		on_scope_end {
 			namespace::clean->clean_subroutines(
 				$caller,
 				keys %{ $self->class_map },
 			);
-		};
+		} unless $self->flags->{ retain };
 	}
 };
 
        },
     ];
 
+The C<< -retain >> flag can be used to indicate that MooX::Struct should
+B<not> use namespace::clean to enforce lexicalness on your struct class
+aliases.
+
 Flags C<< -trace >> and C<< -deparse >> may be of use debugging.
 
 =head2 Instantiating Structs

lib/MooX/Struct/Util.pm

 package MooX::Struct::Util;
 
 our $AUTHORITY = 'cpan:TOBYINK';
-our $VERSION   = '0.006';
+our $VERSION   = '0.007';
 
 use strict;
 use Sub::Install qw(install_sub);

meta/changes.pret

 		item "New experimental method 'EXTEND'."^^Addition;
 		item "Dropped 'object_id' alias for 'OBJECT_ID'."^^Removal;
 	].
+
+`MooX-Struct 0.007 cpan:TOBYINK`
+	issued  2012-10-28;
+	changeset [
+		item "Allow namespace::clean behaviour to be avoided via a '-retain' flag."^^Addition;
+	].
+use Test::More;
+
+{
+	package Local::Foo1;
+	use MooX::Struct
+		Bar => [qw($name)],
+	;
+	
+	::ok(
+		Bar->can('name'),
+		'Bar class available inside Local::Foo1',
+	);
+}
+
+{
+	package Local::Foo2;
+	use MooX::Struct -retain,
+		Bar => [qw($name)],
+	;
+	
+	::ok(
+		Bar->can('name'),
+		'Bar class available inside Local::Foo2',
+	);
+}
+
+::ok(
+	!'Local::Foo1'->can('Bar'),
+	"Bar class unavailable outside Local::Foo1",
+);
+
+::ok(
+	'Local::Foo2'->can('Bar'),
+	"Bar class available outside Local::Foo2",
+);
+
+::ok(
+	Local::Foo2::Bar->can('name'),
+	"Bar class works outside Local::Foo2",
+);
+
+done_testing;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.