App-HTTPThis
view release on metacpan or search on metacpan
lib/App/HTTPThis.pm view on Meta::CPAN
sub new {
my $class = shift;
my $self = bless {host => '127.0.0.1', port => 7007, root => '.'}, $class;
my $default_config_file = '.http_thisrc';
my $config_file = $self->{config} || $ENV{HTTP_THIS_CONFIG};
{
my %early;
local @ARGV = @ARGV;
Getopt::Long::Configure(qw(pass_through));
GetOptions(\%early, "config=s") || pod2usage(2);
Getopt::Long::Configure(qw(default));
$config_file = $early{config} if defined $early{config};
}
# There are apparently OSes where $ENV{HOME} is undefined
for my $dir ('.', $ENV{HOME}) {
next unless defined $dir;
if (!$config_file && -f "$dir/$default_config_file") {
t/default-host.t view on Meta::CPAN
my $dir = tempdir(CLEANUP => 1);
my $file = "$dir/http_thisrc";
open my $fh, '>', $file or die "cannot create config '$file': $!";
print {$fh} $contents;
close $fh;
return $file;
}
sub new_app {
my (@argv) = @_;
local @ARGV = @argv;
my $orig = getcwd();
my $tmp = tempdir(CLEANUP => 1);
local $ENV{HOME} = $tmp;
chdir $tmp or die "cannot chdir to '$tmp': $!";
my $app = App::HTTPThis->new;
chdir $orig or die "cannot chdir back to '$orig': $!";
return $app;
}
subtest 'defaults host to localhost when unset' => sub {
( run in 1.542 second using v1.01-cache-2.11-cpan-a9496e3eb41 )