File Coverage

blib/lib/SDL/Internal/Loader.pm
Criterion Covered Total %
statement 24 24 100.0
branch 6 10 60.0
condition 2 3 66.6
subroutine 5 5 100.0
pod 0 1 0.0
total 37 43 86.0


line stmt bran cond sub pod time code
1             package SDL::Internal::Loader;
2 55     55   371 use strict;
  55         156  
  55         1570  
3 55     55   323 use warnings;
  55         109  
  55         4235  
4             require Exporter;
5             our @ISA = qw(Exporter);
6             our @EXPORT = qw(internal_load_dlls);
7             our @LIBREFS = ();
8              
9 55     55   36164 use SDL::ConfigData;
  55         232  
  55         2176  
10 55     55   30506 use Alien::SDL;
  55         2474235  
  55         10837  
11              
12             our $VERSION = 2.548;
13              
14             # SDL::Internal::Loader is a king of "Dynaloader kung-fu" that is
15             # necessary in situations when you install Allien::SDL from sources
16             # or from prebuilt binaries as in these scenarios the SDL stuff is
17             # installed into so called 'sharedir' somewhere in perl/lib/ tree
18             # on Windows box it is e.g.
19             # C:\strawberry\perl\site\lib\auto\share\dist\Alien-SDL...
20             #
21             # What happens is that for example XS module "SDL::Video" is linked
22             # with -lSDL library which means that resulting "Video.(so|dll)" has
23             # a dependency on "libSDL.(so|dll)" - however "libSDL.(so|dll)" is
24             # neither in PATH (Win) or in LD_LIBRARY_PATH (Unix) so Dynaloader
25             # will fail to load "Video.(so|dll)".
26             #
27             # To handle this we have internal_load_dlls() which has to be called
28             # from XS modules (e.g. SDL::Video) linked with SDL libs like this:
29             #
30             # use SDL::Internal::Loader;
31             # internal_load_dlls(PACKAGE);
32              
33             sub internal_load_dlls($) {
34 427     427 0 1096 my $package = shift;
35             ### check if some ld_shlib_map is defined
36 427         2368 my $shlib_map = Alien::SDL->config('ld_shlib_map');
37 427 50       138425 return unless $shlib_map; # empty shlib_map, nothing to do
38              
39             ### get list of lib nicknames based on packagename
40 427         2671 my $lib_nick = SDL::ConfigData->config('SDL_lib_translate')->{$package};
41 427 50       1068 return unless $lib_nick; # no need to load anything
42              
43             ### let us load the corresponding shlibs (*.dll|*.so)
44 427         2212 require DynaLoader;
45 427         1064 foreach my $n (@$lib_nick) {
46 507         1090 my $file = $shlib_map->{$n};
47 507 100 66     10479 next unless $file && -e $file;
48 505         23771 my $libref = DynaLoader::dl_load_file( $file, 0 );
49 505 50       2981 push( @DynaLoader::dl_librefs, $libref ) if $libref;
50 505 50       2557 push( @LIBREFS, $libref ) if $libref;
51             }
52             }
53              
54             1;