Commits

Toby Inkster committed 3bd90ed

reintroduce namespace::clean trickery; fix test cases to pass

  • Participants
  • Parent commits eb120c4

Comments (0)

Files changed (4)

File lib/IO/Detect.pm

 		smartmatch => [qw( FileHandle FileName FileUri )],
 	},
 	installer => sub {
-#		namespace::clean::->import(
-#			-cleanee => $_[0]{into},
-#			grep { !ref } @{ $_[1] },
-#		);
+		namespace::clean::->import(
+			-cleanee => $_[0]{into},
+			grep { !ref } @{ $_[1] },
+		);
 		goto \&Sub::Exporter::default_installer;
 	},
 };
 		default            { die "$file is not a file!" }
 	}
 
-=head2 Duck Typing
+=head2 Export
+
+Like Scalar::Does, IO::Detect plays some tricks with L<namespace::clean> to
+ensure that any functions it exports to your namespace are cleaned up when
+you're finished with them.
+
+=head3 Duck Typing
 
 In some cases you might be happy to accept something less than a
 complete file handle. In this case you can import a customised
 
 Various other modules that may be of interest, in no particular
 order...
+L<Scalar::Does>,
 L<Scalar::Util>,
-L<Scalar::Does>,
 L<FileHandle>,
 L<IO::Handle>,
 L<IO::Handle::Util>,

File t/iod-02filehandles.t

 	foreach (@handles)
 	{
 		my ($truth, $label, $fh) = @$_;
-		
-		if ($truth)
-		{
-			eval q[ ok($fh ~~ FileHandle, "smart match positive for $label") ];
-		}
-		else
-		{
-			eval q[ ok(not($fh ~~ FileHandle), "smart match negitive for $label") ];
-		}
+		my $eval = $truth
+			? q[ ok($fh ~~ FileHandle, "smart match positive for $label") ]
+			: q[ ok(not($fh ~~ FileHandle), "smart match negitive for $label") ];
+		eval "use IO::Detect -smartmatch; $eval";
 	}
 }
 

File t/iod-03filenames.t

 ok !is_filename(''), 'is_filename empty string';
 
 if ($] >= 5.010)
-{
+{	
 	eval q[
+		use IO::Detect -smartmatch, -default;
+		
 		ok(is_filename, "is_filename $_") for @filenames;
 
 		ok not([]    ~~ FileName), 'ARRAY ~~ FileName';

File t/iod-04fileuris.t

 if ($] >= 5.010)
 {
 	eval q[
+		use IO::Detect -smartmatch, -default;
 		ok(is_fileuri, sprintf("is_fileuri %s %s", ref $_, $_)) foreach @uris;
 		ok($_ ~~ FileUri, sprintf("is_fileuri %s %s", ref $_, $_)) foreach @uris;
 	];
 }
 
 ok not is_fileuri 'http://localhost/';
-
 ok not is_fileuri "http://localhost/\nfile://";
 
 done_testing();