diff --git a/lib/App/Prove.pm b/lib/App/Prove.pm index ab4300c4..82af4494 100644 --- a/lib/App/Prove.pm +++ b/lib/App/Prove.pm @@ -4,6 +4,7 @@ use strict; use warnings; use TAP::Harness::Env; +use TAP::Harness::Runtime qw (IS_UNIXY IS_VMS IS_WIN32); use Text::ParseWords qw(shellwords); use File::Spec; use Getopt::Long; @@ -40,10 +41,6 @@ wrapper around an instance of this module. =cut -use constant IS_WIN32 => ( $^O =~ /^(MS)?Win32$/ ); -use constant IS_VMS => $^O eq 'VMS'; -use constant IS_UNIXY => !( IS_VMS || IS_WIN32 ); - use constant STATE_FILE => IS_UNIXY ? '.prove' : '_prove'; use constant RC_FILE => IS_UNIXY ? '.proverc' : '_proverc'; diff --git a/lib/App/Prove/State.pm b/lib/App/Prove/State.pm index 08ec936c..c224c278 100644 --- a/lib/App/Prove/State.pm +++ b/lib/App/Prove/State.pm @@ -10,13 +10,14 @@ use Carp; use App::Prove::State::Result; use TAP::Parser::YAMLish::Reader (); use TAP::Parser::YAMLish::Writer (); +use TAP::Harness::Runtime qw (IS_WIN32); + use base 'TAP::Base'; BEGIN { __PACKAGE__->mk_methods('result_class'); } -use constant IS_WIN32 => ( $^O =~ /^(MS)?Win32$/ ); use constant NEED_GLOB => IS_WIN32; =head1 NAME diff --git a/lib/TAP/Base.pm b/lib/TAP/Base.pm index c203dee8..a69fe1bb 100644 --- a/lib/TAP/Base.pm +++ b/lib/TAP/Base.pm @@ -5,6 +5,8 @@ use warnings; use base 'TAP::Object'; +use TAP::Harness::Runtime qw (time HAS_TIME_HIRES); + =head1 NAME TAP::Base - Base class that provides common functionality to L @@ -18,10 +20,7 @@ Version 3.51_01 our $VERSION = '3.51_01'; -use constant GOT_TIME_HIRES => do { - eval 'use Time::HiRes qw(time);'; - $@ ? 0 : 1; -}; +use constant GOT_TIME_HIRES => HAS_TIME_HIRES; =head1 SYNOPSIS diff --git a/lib/TAP/Formatter/Color.pm b/lib/TAP/Formatter/Color.pm index b9d909a0..82e9c67b 100644 --- a/lib/TAP/Formatter/Color.pm +++ b/lib/TAP/Formatter/Color.pm @@ -3,7 +3,7 @@ package TAP::Formatter::Color; use strict; use warnings; -use constant IS_WIN32 => ( $^O =~ /^(MS)?Win32$/ ); +use TAP::Harness::Runtime qw (IS_WIN32); use base 'TAP::Object'; diff --git a/lib/TAP/Harness/Env.pm b/lib/TAP/Harness/Env.pm index a70e56e4..cb1d249f 100644 --- a/lib/TAP/Harness/Env.pm +++ b/lib/TAP/Harness/Env.pm @@ -3,7 +3,8 @@ package TAP::Harness::Env; use strict; use warnings; -use constant IS_VMS => ( $^O eq 'VMS' ); +use TAP::Harness::Runtime qw (IS_VMS); + use TAP::Object; use Text::ParseWords qw/shellwords/; diff --git a/lib/TAP/Harness/Runtime.pm b/lib/TAP/Harness/Runtime.pm new file mode 100644 index 00000000..8125e508 --- /dev/null +++ b/lib/TAP/Harness/Runtime.pm @@ -0,0 +1,125 @@ +package TAP::Harness::Runtime; + +use strict; +use warnings; + +use base q (Exporter); + +use Time::HiRes; + +use constant HAS_TIME_HIRES => !! eval { + require Time::HiRes; + Time::HiRes->import (qw (time)); + 1 +}; + +use constant IS_VMS => $^O eq q (VMS); +use constant IS_WIN32 => ($^O =~ qr (^ (MS) Win32 $)x); +use constant IS_UNIXY => ! (IS_VMS || IS_WIN32); + +my @constants = qw ( + IS_VMS + IS_WIN32 + IS_UNIXY + HAS_TIME_HIRES +); + +our @EXPORT_OK = ( + @constants, + HAS_TIME_HIRES ? qw (time) : (), +); + +our %EXPORT_TAGS = ( + all => \ @EXPORT_OK, + constants => \ @constants, +); + +sub import { + my ($caller, @arguments) = @_; + + # 'time' is exported only when Time::HiRes is available + # but can be always requested + @arguments = grep { $_ ne q (time) } @arguments + unless HAS_TIME_HIRES + ; + + local @_ = ($caller, @arguments); + goto \ &Exporter::import; +} + +1; + +__END__ + +=pod + +=encoding utf8 + +=head1 NAME + +TAP::Harness::Runtime - constants to identify runtime environment + +=head1 SYNOPSIS + + package My:Superb::Package; + + # import constants + use TAP::Harness::Runtime qw (:constants); + +=head1 DESCRIPTION + +Module wraps runtime detection used by multiple modules into single module. + +=head1 EXPORTABLE FUNCTIONS + +=head2 HAS_TIME_HIRES + +Constant evaluating as C when module L is importable. + +=head2 IS_VMS + +Constant evaluating as C when running on VMS. + +=head2 IS_WIN32 + +Constant evaluating as C when running on Windows (32-bit or 64-bit) + +=head2 IS_UNIXY + +Constant evaluating as C when running system which behaves like Unix. + +=head2 time + +When L is available module reexports its C