This file is indexed.

/usr/lib/perl5/Module/Build/SDL.pm is in libsdl-perl 2.540-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
package Module::Build::SDL;
use strict;
use warnings;
use base 'Module::Build';

__PACKAGE__->add_property(parinput  => '');
__PACKAGE__->add_property(paroutput => '');
__PACKAGE__->add_property(parlibs   => [ qw/SDL SDL-1.2 SDLmain/ ]);
__PACKAGE__->add_property(parmods   => []);

use File::Spec;
use File::Find qw[finddepth];
use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
use Alien::SDL;

sub new {
  my $self = shift;
  my %args = @_;  
  $args{share_dir} ||= 'data'; #set default sharedir name 'data' instead of 'share'
  $self->SUPER::new(%args);
}

sub ACTION_par {
  my ($self) = @_;
  $self->depends_on('code');
  $self->depends_on('installdeps');
  
  #checking if we have the pp installed
  die 'Need PAR::Packer' if !( eval ' use PAR::Packer; 1' );

  #here comes the code from https://github.com/PerlGameDev/SDL-Par-Packager/blob/master/SDLpp.pl
  my $output = $self->paroutput || (($^O eq 'MSWin32') ? 'a.exe' : 'a');
  my $input = $self->parinput;
  my @sdl_libs = @{$self->parlibs};  
  my $extra = join ' ', (map {"-M$_"} @{$self->parmods}); # = '-MModname::A -MModname::B ...'
  my $Include = './lib';

  die 'parinput needs to be specified' unless $input;

  print "BUILDING PAR \n";
  my $exclude_modules = '-X Alien::SDL::ConfigData -X SDL::ConfigData';
  my $include_modules = '-M ExtUtils::CBuilder::Base -M Data::Dumper -M SDL -M Alien::SDL';
  $include_modules .= " $extra" if $extra;

  my $out_par = $output . '.par';
  my $par_cmd = "pp -B $exclude_modules $include_modules";
  $par_cmd .= " -I $Include" if $Include;
  $par_cmd .= " -p -o $out_par $input";
  print "\t $par_cmd \n";
  `$par_cmd` if !-e $out_par;

  print "PAR: $out_par\n" if -e $out_par;

  print "SEARCHING FOR ConfigData files \n";
  my $lib;
  my $AS_path;
  my $SD_path;

  finddepth( sub {
               my ($f, $d) = ($File::Find::name, $File::Find::dir);
  	       if ( $_ =~ /ConfigData/ ) {
  		  $AS_path = $f if $f =~ 'Alien/SDL/ConfigData.pm';
  		  $SD_path = $f if $f =~ 'SDL/ConfigData.pm' && $f !~ 'Alien/SDL/ConfigData.pm';
  		  $lib = $d if ( $AS_path && $SD_path );
  	       }
             }, @INC );

  die "Cannot find lib/SDL/ConfigData.pm or lib/Alien/SDL/ConfigData.pm \n" if ( !$AS_path || !$SD_path );

  print "Found ConfigData files in $lib \n";

  print "READING PAR FILE \n";

  my $par_file = Archive::Zip->new();
  unless ( $par_file->read($out_par) == AZ_OK ) {
    die 'read error on ' . $out_par;
  }

  $par_file->addFile( $AS_path, 'lib/Alien/SDL/ConfigData.pm' );
  $par_file->addFile( $SD_path, 'lib/SDL/ConfigData.pm' );

  my $share = Alien::SDL::ConfigData->config('share_subdir');

  my @shares = $par_file->membersMatching($share);

  my $alien_sdl_auto = $shares[0]->fileName;

  $alien_sdl_auto =~ s/$share(\S+)// if $alien_sdl_auto;

  my @auto_folder = $par_file->membersMatching("$alien_sdl_auto(?!$share)");

  my @sdl_not_runtime = $par_file->membersMatching( $share . '/include' ); #TODO remove extra fluff in share_dri
  push @sdl_not_runtime, @auto_folder;                                     #remove non share dir stuff
  push @sdl_not_runtime, $par_file->membersMatching( $share . '/etc' );
  push @sdl_not_runtime, $par_file->membersMatching( $share . '/share' );
  push @sdl_not_runtime, $par_file->membersMatching( $share . '/lib' ) if $^O eq 'MSWin32';

  my @non              = ();
  my @sdl_libs_to_keep = ();

  foreach (@sdl_libs) {
    if ( $^O eq 'MSWin32' ) {
      @non = $par_file->membersMatching( $share . "/bin(\\S+)" );
      #push @sdl_not_runtime ,$par_file->membersMatching( $share."/bin(\\S+)(?!$_)" )
    }
    else {
      @non = $par_file->membersMatching( $share . "/lib(\\S+)" );
    }

    print "Removing non $_ shared objs \n";
    my $lib_look = 'lib' . $_;
    map {
      my $n = $_->fileName;
      if ( $n =~ /$lib_look\.(so|a|dll|dylib)/ ) {
        push( @sdl_libs_to_keep, $_ );
      }
    } @non;
  }

  print "found $#sdl_libs_to_keep sdl libs to keep \n";
  my $regex_search = ']';
  map {
    print "\t " . $_->fileName . "\n";
    $regex_search .= ']' . $_->fileName
  } @sdl_libs_to_keep;

  $regex_search =~ s/\]\]//g;
  $regex_search =~ s/\]/\|/g;

  $regex_search = '(' . $regex_search . ')';

  map {
    my $n    = $_->fileName;
    my $star = ' ';

    if ( $n !~ $regex_search ) {
      push @sdl_not_runtime, $_;
    }
  } @non;

  push @sdl_not_runtime, $par_file->membersMatching( $share . '/bin' )
  	unless $^O eq 'MSWin32';
  print "REMOVING NON RUNTIME $#sdl_not_runtime files from  \n";
  open( my $FH, '>', 'DeleteRecords.txt' ) or die $!;
  foreach (@sdl_not_runtime) {
    if ( $_->fileName eq $alien_sdl_auto . $share ) {
      print $FH "Not deleting " . $_->fileName . " \n";
    }
    else {
      $par_file->removeMember($_);
      print $FH $_->fileName . "\n";
    }
  }
  close $FH;

  my @config_members = $par_file->membersMatching('ConfigData.pm');

  foreach (@config_members) {
    $_->desiredCompressionLevel(1);
    $_->unixFileAttributes(0644);
  }

  unlink $out_par . '2';
  unless ( $par_file->writeToFileNamed( $out_par . '2' ) == AZ_OK ) {
    die 'write error';
  }

  $par_cmd = "pp -o $output " . $out_par . "2";

  `$par_cmd`;

  print "MADE $output \n" if -e $output;
  unlink $out_par . '2';
  unlink $out_par; 
}

sub ACTION_run {
  my ($self) = @_;
  $self->depends_on('code');
  $self->depends_on('installdeps');
  my $bd = $self->{properties}->{base_dir};

  # prepare INC
  local @INC = @INC;
  local @ARGV = @{$self->args->{ARGV}};
  my $script = shift @ARGV;
  unshift @INC, (File::Spec->catdir($bd, $self->blib, 'lib'), File::Spec->catdir($bd, $self->blib, 'arch'));

  if ($script) {
    # scenario: ./Build run bin/scriptname param1 param2
    do($script);
  }
  else {
    # scenario: ./Build run
    my ($first_script) = ( glob('bin/*') ); # take the first script in bin subdir
    print STDERR "No params given to run action - gonna start: '$first_script'\n";
    do($first_script);
  }
}

# TODO: later move app skeleton generation into SDL::Devel (or something like this)
sub generate_sdl_module {
  my ($path, $name) = @_;

  #Make the path and directory stuff
  mkdir $path or
  Carp::croak "Cannot make a SDL based module at $path : $!";

  mkdir "$path/lib";
  mkdir "$path/bin";
  mkdir "$path/data";

  open my $FH, ">>$path/bin/sdl_app.pl";

  print $FH "use string;\nuse warnings;\nuse SDL;\n";

  close $FH;

  open  $FH, ">>$path/Build.PL";

  print $FH 
  "use strict;\nuse warnings;\nuse Module::Build::SDL;
  my \$builder = Module::Build::SDL->new(
    module_name => '$name',
    dist_version => '1.01',
    dist_abstract => 'Put something in here',
    dist_author => 'developer <developer\@example.com>',
    license => 'perl',
  )->create_build_script();
  ";
}

1;

__END__

=head1 NAME

Module::Build::SDL - Module::Build subclass for building SDL apps/games [not stable yet]

=head1 SYNOPSIS

When creating a new SDL application/game you can create Build.PL like this:

 use Module::Build::SDL;
   
 my $builder = Module::Build::SDL->new(
     module_name   => 'Games::Demo',
     dist_version  => '1.00',
     dist_abstract => 'Demo game based on Module::Build::SDL',
     dist_author   => 'coder@cpan.org',
     license       => 'perl',
     requires      => {
         'SDL'     => 0,
     },
     #+ others Module::Build options
 )->create_build_script();

Once you have created a SDL application/game via Module::Build::SDL as described
above you can use some extra build targets/actions:

=over

=item * you can create a PAR distribution like:

 $ perl ./Build.PL
 $ ./Build
 $ ./Build par

There are some extra parameters related to 'par' action you can pass to Module::Build::SDL->new():

 parinput  => 'bin/scriptname.pl'
 paroutput => 'filename.par.exe',
 parlibs   => [ qw/SDL SDL_main SDL_gfx/ ],  #external libraries (.so/.dll) to be included into PAR
 parmods   => [ qw/Module::A Module::B/ ],   #extra modules to be included into PAR

=item * to run the game from distribution directory you can use:

 $ perl ./Build.PL
 $ ./Build
 $ ./Build run

=item * TODO: maybe some additional actions: parexe, parmsi, deb, rpm

=back

=head1 DESCRIPTION

Module::Build::SDL is a subclass of L<Module::Build|Module::Build> created
to make easy some tasks specific to SDL applications - e.g. packaging SDL
application/game into PAR archive.

=head1 APPLICATION/GAME LAYOUT

Module::Build::SDL expects the following layout in project directory:

 #example: game with the main *.pl script + data files + modules (*.pm)
 Build.PL
 lib/
     Games/
           Demo.pm
 bin/
     game-script.pl
 data/
     whatever_data_files_you_need.jpg

the most simple game should look like:

 #example: simple one-script apllication/game
 Build.PL
 bin/
    game-script.pl

In short - there are 3 expected subdirectories:

=over

=item * B<bin> - one or more perl scripts (*.pl) to start the actual
application/game

=item * B<lib> - application/game specific modules (*.pm) organized
in dir structure in "usual perl manners"

=item * B<data> - directory for storing application data (pictures, 
sounds etc.). This subdirectory is handled as a "ShareDir"
(see L<File::ShareDir|File::ShareDir> for more details)

=item * As the project is (or could be) composed as a standard perl
distribution it also support standard subdirectory B<'t'> (with tests).

=back

=head1 RULES TO FOLLOW

When creating a SDL application/game based on Module::Build::SDL it is
recommended to follow these rules:

=over

=item * Use the name for your game from I<Games::*> namespace; it will make
the later release to CPAN much easier.

=item * Put all data files into B<data> subdirectory and access the B<data>
subdir only via L<File::ShareDir|File::ShareDir> 
(namely by calling L<distdir()|File::ShareDir/dist_dir> function)

=item * TODO: maybe add more

=back

=cut