Commits

Toby Inkster committed 057bb59

PERL_ASK_BACKEND environment variable

Comments (0)

Files changed (3)

 	sub _detect_class {
 		my ($class, $args) = @_;
 		
+		if (exists $ENV{PERL_ASK_BACKEND}) {
+			return use_package_optimistically($ENV{PERL_ASK_BACKEND});
+		}
+		
 		if (exists $args->{class}) {
 			return use_package_optimistically(delete $args->{class});
 		}
 		if (-t STDIN and -t STDOUT) {
 			return use_module("Ask::STDIO");
 		}
-
+		
 		if (eval { require Ask::Tk }) {
 			return 'Ask::Tk';
 		}
-
+		
 		if (my $zenity = which('zenity')) {
 			$args->{zenity} //= $zenity;
 			return use_module("Ask::Zenity");
 			$self->entry(%o);
 		}
 	}
-
+	
 	my $ask = Ask->detect(traits => ['AskX::Method::Password']);
 	say "GOT: ", $ask->password;
 
+=head1 ENVIRONMENT
+
+The C<PERL_ASK_BACKEND> environment variable can be used to influence the
+outcome of C<< Ask->detect >>. Indeed, it trumps all other factors. If set,
+it should be a full class name.
+
 =head1 BUGS
 
 Please report any bugs to
 
 See L<Ask::API> for documentation of API internals.
 
-Bundled API implementations are L<Ask::STDIO> and L<Ask::Zenity>.
+Bundled API implementations are L<Ask::STDIO>, L<Ask::Zenity> and L<Ask::Tk>.
 
 Similar modules: L<IO::Prompt>, L<IO::Prompt::Tiny> and many others.
 
 use warnings;
 use Test::More;
 
+BEGIN { delete $ENV{PERL_ASK_BACKEND} };
+
 use Ask;
 
 my @input;
 use warnings;
 use Test::More;
 
+BEGIN { delete $ENV{PERL_ASK_BACKEND} };
+
 use Ask;
 
 my @input;