/usr/share/perl5/Games/FrozenBubble/MDKCommon.pm is in frozen-bubble 2.212-3ubuntu3.
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 | package Games::FrozenBubble::MDKCommon;
use 5.006;
use strict;
use warnings;
our @ISA = 'Exporter';
our @EXPORT = qw{
$PI cat_ member difference2 any even odd sqr to_bool to_int if_
fold_left output append_to_file min max backtrace basename cp_af all
};
our $PI = 3.1415926535897932384626433832795028841972;
sub cat_ {
local *F;
open F, $_[0] or return;
my @l = <F>;
wantarray ? @l : join '', @l;
}
sub member {
my $e = shift;
foreach (@_) { $e eq $_ and return 1 }
0;
}
sub difference2 {
my %l;
@l{ @{ $_[1] } } = ();
grep { !exists $l{$_} } @{ $_[0] };
}
sub any(&@) {
my $f = shift;
$f->($_) and return 1 foreach @_;
0;
}
sub even { $_[0] % 2 == 0 }
sub odd { $_[0] % 2 == 1 }
sub sqr { $_[0] * $_[0] }
sub to_bool { $_[0] ? 1 : 0 }
sub to_int { $_[0] =~ /(\d*)/; $1 }
sub if_($@) {
my $b = shift;
$b or return ();
wantarray || @_ <= 1
or die( "if_ called in scalar context with more than one argument "
. join( ":", caller() ) );
wantarray ? @_ : $_[0];
}
sub fold_left(&@) {
my ( $f, $initial, @l ) = @_;
local ( $::a, $::b );
$::a = $initial;
foreach $::b (@l) { $::a = &$f() }
$::a;
}
sub output {
my $f = shift;
local *F;
open F, ">$f" or die "output in file $f failed: $!\n";
print F foreach @_;
}
sub append_to_file {
my $f = shift;
local *F;
open F, ">>$f" or die "output in file $f failed: $!\n";
print F foreach @_;
1;
}
sub min { my $n = shift; $_ < $n and $n = $_ foreach @_; $n }
sub max { my $n = shift; $_ > $n and $n = $_ foreach @_; $n }
sub backtrace {
my $s;
for ( my $i = 1 ; caller($i) ; $i++ ) {
my ( $package, $file, $line, $func ) = caller($i);
$s .= "$func() called from $file:$line\n";
}
$s;
}
sub basename { local $_ = shift; s|/*\s*$||; s|.*/||; $_ }
sub cp_af {
my $dest = pop @_;
@_ or return;
@_ == 1 || -d $dest
or die
"cp: copying multiple files, but last argument ($dest) is not a directory\n";
foreach my $src (@_) {
my $dest = $dest;
-d $dest and $dest .= '/' . basename($src);
unlink $dest;
if ( -d $src ) {
-d $dest
or mkdir $dest, ( stat($src) )[2]
or die "mkdir: can't create directory $dest: $!\n";
cp_af( glob_($src), $dest );
}
elsif ( -l $src ) {
unless (
symlink(
( readlink($src) || die "readlink failed: $!" ), $dest
)
)
{
warn "symlink: can't create symlink $dest: $!\n";
}
}
else {
local *F;
open F, $src or die "can't open $src for reading: $!\n";
local *G;
open G, "> $dest";
local $_;
while (<F>) { print G $_ }
chmod( ( stat($src) )[2], $dest );
}
}
1;
}
sub all {
my $d = shift;
local *F;
opendir F, $d or return;
my @l = grep { $_ ne '.' && $_ ne '..' } readdir F;
closedir F;
@l;
}
1;
__END__
=encoding UTF-8
=head1 DESCRIPTION
This is extracted from MDK::Common, a helper library that
extends perl capabilities for very common use when programming
perl, especially with functional style programming (but what
other style one could decently adopt? ;p).
This extract is provided here because only Mandrake distro
includes the whole MDK::Common, so you're not obliged to
install it.
That said, if you're a perl programmer, I strongly advice you
to have a look at this library and use it, it would
dramatically increase the efficiency and readability of your
perl programs.
Go to google and type in "perl-MDK-Common" if interested.
|