File Coverage

blib/lib/Devel/FakeOSName.pm
Criterion Covered Total %
statement 17 17 100.0
branch 3 6 50.0
condition 1 3 33.3
subroutine 5 5 100.0
pod n/a
total 26 31 83.8


line stmt bran cond sub pod time code
1             package Devel::FakeOSName;
2              
3 1     1   838 use strict;
  1         2  
  1         32  
4 1     1   5 use warnings;
  1         1  
  1         127  
5              
6             require Config;
7              
8             $Devel::FakeOSName::VERSION = '0.01';
9              
10             {
11             my $orig_STORE = *Config::STORE{CODE};
12             undef &Config::STORE;
13             *Config::STORE = sub {
14 1 50 33 1   10 goto &$orig_STORE unless defined $_[1] && $_[1] eq 'osname';
15 1 50       3 die "an osname string must be passed" unless defined $_[2];
16              
17             # modify it once and immediately reset to the normal read-only state
18 1         7 $_[0]->{osname} = $_[2];
19             #undef &Config::STORE; # can't undef an active sub
20 1     1   13 no warnings 'redefine';
  1         1  
  1         123  
21 1         34 *Config::STORE = $orig_STORE;
22 1         13 return $_[2];
23             };
24             }
25              
26             sub import {
27 1     1   358 my($package, $os) = @_;
28              
29 1 50       4 return unless $os;
30              
31             # read/write
32 1         6 $^O = $Config::Config{osname} = $os;
33             }
34              
35              
36             1;
37              
38             =pod
39              
40             =head1 NAME
41              
42             Devel::FakeOSName - Make Perl think it runs on a different OS
43              
44             =head1 SYNOPSIS
45              
46             # build us Makefile for aix
47             perl -MDevel::FakeOSName=aix Makefile.PL
48              
49             =head1 DESCRIPTION
50              
51             Sometimes your code includes code specific to an OS that you don't
52             have an access to, but you want to see what happens if it was to run
53             on that other OS.
54              
55             Currently mostly useful for looking at generated Makefiles. Needs much
56             more work to be really useful.
57              
58             =head1 TODO
59              
60             Currently the module just modifies $^O and $Config{osname}. Could
61             probably somehow supply overrides for other %Config::Config values and
62             ExtUtils::Embed.
63              
64             Patches are welcome.
65              
66             =cut
67