File Coverage

blib/lib/Alien/TinyCC.pm
Criterion Covered Total %
statement 24 25 96.0
branch 3 6 50.0
condition n/a
subroutine 9 10 90.0
pod 4 4 100.0
total 40 45 88.8


line stmt bran cond sub pod time code
1             package Alien::TinyCC;
2              
3 3     3   66796 use strict;
  3         6  
  3         118  
4 3     3   16 use warnings;
  3         8  
  3         158  
5              
6             # Follow Golden's Version Rule: http://www.dagolden.com/index.php/369/version-numbers-should-be-boring/
7             our $VERSION = "0.05";
8             $VERSION = eval $VERSION;
9              
10 3     3   5449 use File::ShareDir;
  3         24581  
  3         208  
11 3     3   39 use File::Spec;
  3         5  
  3         69  
12 3     3   6040 use Env qw( @PATH );
  3         10153  
  3         20  
13 3     3   518 use Carp;
  3         7  
  3         1466  
14              
15             ###################################
16             # Find the Distribution Directory #
17             ###################################
18              
19             # The prefix will depend on whether or not the thing was finally installed.
20             # The easiest way to know that is if *this* *module* *file* is in a blib
21             # directory or not:
22             my $dist_dir;
23              
24             my $mod_path = $INC{'Alien/TinyCC.pm'};
25             if ($mod_path =~ s/(.*)blib.*/$1share/) {
26             $dist_dir = $mod_path;
27             croak('Looks like Alien::TinyCC is being invoked from blib, but I cannot find build-time sharedir!')
28             unless -d $dist_dir;
29             }
30             else {
31             $dist_dir = File::ShareDir::dist_dir('Alien-TinyCC');
32             }
33              
34             ############################
35             # Path retrieval functions #
36             ############################
37              
38             # Find the path to the tcc executable
39             sub path_to_tcc {
40 4 50   4 1 38 return $dist_dir if $^O =~ /MSWin/;
41 4         93 return File::Spec->catdir($dist_dir, 'bin');
42             }
43              
44             # Modify the PATH environment variable to include tcc's directory
45             unshift @PATH, path_to_tcc();
46              
47             # Find the path to the compiled libraries. Note that this is only applicable
48             # on Unixish systems; Windows simply uses the %PATH%, which was already
49             # appropriately set.
50             sub libtcc_library_path {
51 4 50   4 1 16 return $dist_dir if $^O =~ /MSWin/;
52 4         75 return File::Spec->catdir($dist_dir, 'lib');
53             }
54              
55             # Add library path on Unixish:
56             if ($ENV{LD_LIBRARY_PATH}) {
57             $ENV{LD_LIBRARY_PATH} = libtcc_library_path() . ':' . $ENV{LD_LIBRARY_PATH};
58             }
59             elsif ($^O !~ /MSWin/) {
60             $ENV{LD_LIBRARY_PATH} = libtcc_library_path();
61             }
62              
63             # Determine path for libtcc.h
64             sub libtcc_include_path {
65 1 50   1 1 17 return File::Spec->catdir($dist_dir, 'libtcc') if $^O =~ /MSWin/;
66 1         210 return File::Spec->catdir($dist_dir, 'include');
67             }
68              
69             ###########################
70             # Module::Build Functions #
71             ###########################
72              
73             sub MB_linker_flags {
74 0     0 1   return ('-L' . libtcc_library_path, '-ltcc');
75             }
76              
77             # version
78              
79             1;
80              
81             __END__