APP-REST-RestTestSuite
view release on metacpan or search on metacpan
lib/APP/REST/RestTestSuite.pm view on Meta::CPAN
if ( $self->{endpoint} && $self->{port} && $self->{base_uri} ) {
$self->{rest_uri_base} =
qq|http://$self->{endpoint}|
. qq|:$self->{port}|
. qq|$self->{base_uri}|;
return; #use the port and uri in config file and return from sub
} elsif ( $self->{endpoint} && $self->{base_uri} ) {
$self->{rest_uri_base} =
qq|http://$self->{endpoint}| . qq|$self->{base_uri}|;
return; #use the uri in config file and return from sub
} elsif ( $self->{endpoint} && $self->{port} ) {
$self->{rest_uri_base} =
qq|http://$self->{endpoint}| . qq|:$self->{port}|;
return;
} elsif ( $self->{endpoint} ) {
$self->{rest_uri_base} = qq|http://$self->{endpoint}|;
return; #use the endpoint in config file and return from sub
} else {
die qq|Endpoint should be configured in the config file\n|;
}
}
sub _init_config_files {
my ( $self, %args ) = @_;
$self->{file}->{config_file} = $args{REST_CONFIG_FILE};
}
sub _init_sample_config_file {
my ( $self, %args ) = @_;
my $separator;
if ( $^O =~ /Win/ ) {
$separator = '\\';
} else {
$separator = '/';
}
my $scfg = getcwd() || $ENV{PWD};
my $scfg_file = $scfg . $separator . 'rest-project-xxxx.txt';
$self->{file}->{sample_config_file} = $scfg_file;
}
sub _init_log_files {
my ( $self, %args ) = @_;
my $separator;
if ( $^O =~ /Win/ ) {
$separator = '\\';
} else {
$separator = '/';
}
my $log_path = $args{LOG_FILE_PATH} || getcwd() || $ENV{PWD};
my $log_dir = $log_path . $separator . 'LOG';
eval { mkpath( $log_dir, 0, 0755 ) unless ( -d $log_dir ); };
if ($@) {
my $err = $@;
$err =~ s/line\s+\d+//g;
die qq|Unable to create LOG directory ERROR: $err\n|;
}
my $log_file = join(
$separator,
(
$log_dir,
(
$self->{html_log_required}
&& ( $self->{html_log_required} =~ /yes/i )
)
? LOG_FILE
. ".html"
: LOG_FILE
)
);
my $error_log_file = join(
$separator,
(
$log_dir,
(
$self->{html_log_required}
&& ( $self->{html_log_required} =~ /yes/i )
)
? ERR_LOG_FILE
. ".html"
: ERR_LOG_FILE
)
);
$self->{file}->{log_file} = $log_file;
$self->{file}->{err_log_file} = $error_log_file;
}
sub _open_fh {
my ( $self, %args ) = @_;
my ( $fh, $err ) = (undef) x 2;
my $file = $args{FILE};
my $mode = $args{MODE};
if ( $mode =~ m/READ/i ) {
open( $fh, '<', "$file" ) or ( $err = 'yes' );
} elsif ( $mode =~ m/WRITE/i ) {
open( $fh, '>', "$file" ) or ( $err = 'yes' );
} elsif ( $mode =~ m/APPEND/i ) {
open( $fh, '>>', "$file" ) or ( $err = 'yes' );
}
if ($err) {
die qq|\nUnable to open file '$file' for $mode\nERROR: $!\n|;
}
return $fh;
}
( run in 1.732 second using v1.01-cache-2.11-cpan-98e64b0badf )