Line # Revision Author
1 8 ahitrov@rambler.ru package Contenido::File;
2
3 use strict;
4 use warnings;
5
6 use Contenido::Globals;
7 use URI;
8 use Data::Dumper;
9 use IO::File;
10 use IO::Scalar;
11 use Contenido::File::Scheme::HTTP;
12 use Contenido::File::Scheme::FILE;
13 use Contenido::DateTime;
14 142 ahitrov use Image::Info qw(image_info dim);
15 8 ahitrov@rambler.ru
16 our $IgnoreErrors = 1;
17
18 128 ahitrov my %translit = (
19 'а' => 'a', 'б' => 'b', 'в' => 'v', 'г' => 'g', 'д' => 'd', 'е' => 'e', 'ё' => 'e', 'ж' => 'zh', 'з' => 'z', 'и' => 'i', 'й' => 'y',
20 'к' => 'k', 'л' => 'l', 'м' => 'm', 'н' => 'n', 'о' => 'o', 'п' => 'p', 'р' => 'r', 'с' => 's', 'т' => 't', 'у' => 'u', 'ф' => 'f', 'х' => 'h',
21 'ц' => 'ts', 'ч' => '4', 'ш' => 'sh', 'щ' => 'sch', 'ъ' => 'y', 'ы' => 'i', 'ь' => 'y', 'э' => 'e', 'ю' => 'u', 'я' => 'a', 'А' => 'A',
22 'Б' => 'B', 'В' => 'V', 'Г' => 'G', 'Д' => 'D', 'Е' => 'E', 'Ё' => 'E', 'Ж' => 'ZH', 'З' => 'Z', 'И' => 'I', 'Й' => 'Y', 'К' => 'K', 'Л' => 'L',
23 'М' => 'M', 'Н' => 'N', 'О' => 'O', 'П' => 'P', 'Р' => 'R', 'С' => 'S', 'Т' => 'T', 'У' => 'U', 'Ф' => 'F', 'Х' => 'H', 'Ц' => 'TS', 'Ч' => '4',
24 'Ш' => 'SH', 'Щ' => 'SCH', 'Ъ' => 'Y', 'Ы' => 'I', 'Ь' => 'Y', 'Э' => 'E', 'Ю' => 'U', 'Я' => 'YA',
25 );
26
27
28 8 ahitrov@rambler.ru sub fetch {
29 my $filename = shift || return;
30 my $fh;
31
32 foreach my $dir (@{$state->{"files_dir"}}) {
33 my $path = $dir . '/' . $filename;
34
35 no strict "refs";
36 $fh = &{"Contenido::File::Scheme::".uc(scheme($path))."::fetch"}($path);
37 return $fh if $fh;
38 }
39 }
40
41 sub store {
42 my $filename = shift || return;
43 my $fh = get_fh(shift) || return;
44
45 my $dt = Contenido::DateTime->new()->set_locale('en')->set_time_zone("UTC");
46
47 my @successful;
48
49 #убираем сдвоенные и более /
50 $filename =~ s#/+#/#g;
51 #убираем начальный /
52 $filename =~ s#^/##;
53
54 foreach my $dir (@{$state->{"files_dir"}}) {
55 seek $fh, 0, 0;
56 my $path = $dir . '/' . $filename;
57
58 no strict "refs";
59 my $return = &{"Contenido::File::Scheme::".uc(scheme($path))."::store"}($path, $fh, $dt);
60 push @successful, $path if $return;
61 }
62
63 if (
64 !@successful or
65 (
66 (scalar @successful != scalar @{$state->{"files_dir"}}) and
67 !$IgnoreErrors
68 )
69 ) {
70 foreach my $path (@successful) {
71 no strict "refs";
72 &{"Contenido::File::Scheme::".uc(scheme($path))."::remove"}($path);
73 }
74 return;
75 }
76 1;
77 }
78
79 sub size {
80 my $filename = shift;
81 my %args = @_;
82
83 my $size;
84
85 #убираем сдвоенные и более /
86 $filename =~ s#/+#/#g;
87 #убираем начальный /
88 $filename =~ s#^/##;
89
90 foreach my $dir (@{$state->{"files_dir"}}) {
91 no strict "refs";
92 my $response = &{"Contenido::File::Scheme::".uc(scheme($dir))."::size"}($dir."/".$filename, %args);
93 return unless defined $response;
94 return if defined $size and $size != $response;
95
96 $size = $response;
97 #TODO
98 last;
99 }
100 return $size;
101 }
102
103 sub remove {
104 my $filename = shift || return;
105
106 #убираем сдвоенные и более /
107 $filename =~ s#/+#/#g;
108 #убираем начальный /
109 $filename =~ s#^/##;
110
111 foreach my $dir (@{$state->{"files_dir"}}) {
112 no strict "refs";
113 &{"Contenido::File::Scheme::".uc(scheme($dir))."::remove"}($dir."/".$filename);
114 }
115
116 1;
117 }
118
119 sub get_fh {
120 my $input = shift;
121 my $fh;
122
123 if (not ref $input) {
124 no strict "refs";
125 $fh = &{"Contenido::File::Scheme::".uc(scheme($input))."::get_fh"}($input);
126 113 ahitrov } elsif ( ref $input eq 'Apache::Upload' ) {
127 $fh = $input->fh;
128 } elsif ((ref $input eq "GLOB") or (ref $input eq 'IO::File')) {
129 8 ahitrov@rambler.ru $fh = $input;
130 } elsif (ref $input eq "SCALAR") {
131 $fh = IO::Scalar->new($input);
132 } else {
133 $log->warning("Path, scalar ref or fh needed");
134 return;
135 }
136
137 return $fh
138 }
139
140 sub scheme {
141 my $uri = shift;
142 my $scheme;
143
144 $scheme = URI->new($uri)->scheme() || "file";
145
146 return $scheme;
147 }
148
149 # sub files_dir {
150 # return unless $_[0];
151 # my $dir;
152
153 # for (scheme($_[0])) {
154 # /http/ && do {
155 # $dir = URI->new($_[0])->canonical();
156 # $dir =~ s|/*$|/|;
157 # last;
158 # };
159 # /file/ && do {
160 # $dir = URI->new($_[0])->path();
161 # $dir =~ s|/*$|/|;
162 # last;
163 # };
164 # }
165
166 # return $dir;
167 # }
168
169 113 ahitrov sub store_image {
170 my $input = shift;
171 my (%opts) = @_;
172 my $object = delete $opts{object} || return;
173 my $attr = delete $opts{attr} || return;
174
175 my ($prop) = grep { $_->{attr} eq $attr } $object->structure;
176 return unless ref $prop;
177 my @preview = exists $prop->{'preview'} && ref $prop->{'preview'} eq 'ARRAY' ? @{$prop->{'preview'}} : exists $prop->{'preview'} && $prop->{'preview'} ? ($prop->{'preview'}) : ();
178 my @crops = exists $prop->{'crop'} && ref $prop->{'crop'} eq 'ARRAY' ? @{$prop->{'crop'}} : exists $prop->{'crop'} && $prop->{'crop'} ? ($prop->{'crop'}) : ();
179 my @shrinks = exists $prop->{'shrink'} && ref $prop->{'shrink'} eq 'ARRAY' ? @{$prop->{'shrink'}} : exists $prop->{'shrink'} && $prop->{'shrink'} ? ($prop->{'shrink'}) : ();
180
181 my $filename = '/images/'.$object->get_file_name() || return;
182 my $filename_tmp = $state->{'tmp_dir'}.'/'.join('_', split('/', $filename));
183
184 my $fh = get_fh($input);
185 return unless ref $fh;
186
187 my $ext;
188 117 ahitrov my $size = 1073741824;
189 if ( not ref $input ) {
190 113 ahitrov $ext = $input =~ /(jpe?g|gif|png)$/i ? lc $1 : 'bin';
191 117 ahitrov if ( scheme($input) eq 'file' ) {
192 $size = (stat $fh)[7];
193 }
194 113 ahitrov } elsif ( ref $input eq 'Apache::Upload' ) {
195 $ext = $input->filename() =~ /(jpe?g|gif|png)$/i ? lc $1 : 'bin';
196 117 ahitrov $size = (stat $fh)[7];
197 } elsif ( $opts{filename} ) {
198 $ext = $opts{filename} =~ /(jpe?g|gif|png)$/i ? lc $1 : 'bin';
199 113 ahitrov }
200 125 ahitrov if ( ref $fh eq 'IO::Scalar' ) {
201 $size = length("$fh");
202 }
203 113 ahitrov $ext ||= 'bin';
204
205 my $fh_tmp = IO::File->new('>'.$filename_tmp.'.'.$ext) || return;
206 my $buffer;
207
208 117 ahitrov $size = sysread $fh, $buffer, $size;
209 113 ahitrov syswrite $fh_tmp, $buffer, $size;
210
211 undef $fh_tmp;
212
213 142 ahitrov my $image_info = image_info($filename_tmp.'.'.$ext);
214 if ( ref $image_info && $image_info->{file_ext} ne $ext ) {
215 rename $filename_tmp.'.'.$ext, $filename_tmp.'.'.$image_info->{file_ext};
216 $ext = $image_info->{file_ext};
217 147 ahitrov } elsif ( !ref $image_info ) {
218 unlink $filename_tmp.'.'.$ext;
219 return undef;
220 142 ahitrov }
221 147 ahitrov my $transformed;
222 if ( exists $prop->{transform} && ref $prop->{transform} eq 'ARRAY' && scalar @{$prop->{transform}} == 2 && $prop->{transform}[0] =~ /(crop|resize|shrink)/ ) {
223 my $c_line;
224 if ( $prop->{transform}[0] eq 'resize' ) {
225 $c_line = $state->{'convert_binary'}.' -resize \''.$prop->{transform}[1].'\' -quality 80 '.$filename_tmp.'.'.$ext.' '.$filename_tmp.'.transformed.'.$ext;
226 } elsif ( $prop->{transform}[0] eq 'crop' ) {
227 my $shave_string;
228 my ($nwidth, $nheight) = $prop->{transform}[1] =~ /(\d+)x(\d+)/i ? ($1, $2) : (0, 0);
229 if ( ($image_info->{width} / $image_info->{height}) > ($nwidth / $nheight) ) {
230 my $shave_pixels = (($image_info->{width} / $image_info->{height}) - ($nwidth / $nheight)) * $image_info->{height};
231 $shave_string = ' -shave '.int($shave_pixels / 2).'x0';
232 } elsif ( ($image_info->{height} / $image_info->{width}) > ($nheight / $nwidth) ) {
233 my $shave_pixels = (($image_info->{height} / $image_info->{width}) - ($nheight / $nwidth)) * $image_info->{width};
234 $shave_string = ' -shave 0x'.int($shave_pixels / 2);
235 }
236 if ( $shave_string ) {
237 my $c_line = $state->{"convert_binary"}." $shave_string $filename_tmp.$ext $filename_tmp.shaved.$ext";
238 my $result = `$c_line`;
239 if (length $result > 0) {
240 print "Contenido Error: При вызове '$c_line' произошла ошибка '$result' ($@)\n";
241 return undef;
242 }
243 } else {
244 my $c_line = "cp $filename_tmp.$ext $filename_tmp.shaved.$ext";
245 my $result = `$c_line`;
246 if (length $result > 0) {
247 print "Contenido Error: При вызове '$c_line' произошла ошибка '$result' ($@)\n";
248 return undef;
249 }
250 }
251 $c_line = $state->{'convert_binary'}.' -geometry \''.$prop->{transform}[1].'!\' -quality 80 '.$filename_tmp.'.shaved.'.$ext.' '.$filename_tmp.'.transformed.'.$ext;
252 } elsif ( $prop->{transform}[0] eq 'shrink' ) {
253 $c_line = $state->{'convert_binary'}.' -geometry \''.$prop->{transform}[1].'!\' -quality 80 '.$filename_tmp.'.'.$ext.' '.$filename_tmp.'.transformed.'.$ext;
254 }
255 my $result = `$c_line`;
256 $transformed = 1;
257 unlink $filename_tmp.'.shaved.'.$ext if -e $filename_tmp.'.shaved.'.$ext;
258 }
259 142 ahitrov
260 113 ahitrov my $IMAGE;
261 147 ahitrov my $stored = $transformed ? store($filename.'.'.$ext, $filename_tmp.'.transformed.'.$ext) : store($filename.'.'.$ext, $filename_tmp.'.'.$ext);
262 if ( $stored ) {
263 113 ahitrov $IMAGE = {};
264 149 ahitrov # hashref slice assigning - жжесть
265 147 ahitrov if ( $transformed && -e $filename_tmp.'.transformed.'.$ext ) {
266 160 ahitrov my ($tw, $th) = Image::Size::imgsize($filename_tmp.'.transformed.'.$ext);
267 my ($w, $h) = Image::Size::imgsize($filename_tmp.'.'.$ext);
268 @{$IMAGE}{'filename', 't_width', 't_height', 'width', 'height'} = (
269 $filename.'.'.$ext, $tw, $th, $w, $h
270 147 ahitrov );
271 unlink $filename_tmp.'.transformed.'.$ext;
272 } else {
273 @{$IMAGE}{'filename', 'width', 'height'} = (
274 $filename.'.'.$ext,
275 Image::Size::imgsize($filename_tmp.'.'.$ext),
276 );
277 }
278 113 ahitrov
279 foreach my $suffix (@preview) {
280 my $c_line = $state->{'convert_binary'}.' -geometry \''.$suffix.'\' -quality 80 '.$filename_tmp.'.'.$ext.' '.$filename_tmp.'.'.$suffix.'.'.$ext;
281 my $result = `$c_line`;
282
283 if (length $result > 0) {
284 warn 'Contenido Error: При вызове "'.$c_line.'" произошла ошибка "'.$result.'" ('.$@.")\n";
285 return undef;
286 }
287 @{$IMAGE->{'mini'}{$suffix}}{'filename', 'width', 'height'} = (
288 $filename.'.'.$suffix.'.'.$ext,
289 Image::Size::imgsize($filename_tmp.'.'.$suffix.'.'.$ext),
290 );
291 %{$IMAGE->{'resize'}{$suffix}} = %{$IMAGE->{'mini'}{$suffix}};
292 store($filename.'.'.$suffix.'.'.$ext, $filename_tmp.'.'.$suffix.'.'.$ext);
293 unlink $filename_tmp.'.'.$suffix.'.'.$ext if -e $filename_tmp.'.'.$suffix.'.'.$ext;
294 }
295 if ( @preview ) {
296 @{$IMAGE->{'mini'}}{'filename', 'width', 'height'} = @{$IMAGE->{'mini'}{$preview[0]}}{'filename', 'width', 'height'};
297 @{$IMAGE->{'resize'}}{'filename', 'width', 'height'} = @{$IMAGE->{'mini'}{$preview[0]}}{'filename', 'width', 'height'};
298 }
299
300 ########## CROPS
301 foreach my $suffix (@crops) {
302
303 my $shave_string;
304 my ($nwidth, $nheight) = $suffix =~ /(\d+)x(\d+)/i ? ($1, $2) : (0, 0);
305 if ( ($IMAGE->{width} / $IMAGE->{height}) > ($nwidth / $nheight) ) {
306 my $shave_pixels = (($IMAGE->{width} / $IMAGE->{height}) - ($nwidth / $nheight)) * $IMAGE->{height};
307 $shave_string = ' -shave '.int($shave_pixels / 2).'x0';
308 } elsif ( ($IMAGE->{height} / $IMAGE->{width}) > ($nheight / $nwidth) ) {
309 my $shave_pixels = (($IMAGE->{height} / $IMAGE->{width}) - ($nheight / $nwidth)) * $IMAGE->{width};
310 $shave_string = ' -shave 0x'.int($shave_pixels / 2);
311 }
312 if ( $shave_string ) {
313 my $c_line = $state->{"convert_binary"}." $shave_string $filename_tmp.$ext $filename_tmp.shaved.$ext";
314 my $result = `$c_line`;
315 if (length $result > 0) {
316 print "Contenido Error: При вызове '$c_line' произошла ошибка '$result' ($@)\n";
317 }
318 } else {
319 my $c_line = "cp $filename_tmp.$ext $filename_tmp.shaved.$ext";
320 my $result = `$c_line`;
321 if (length $result > 0) {
322 print "Contenido Error: При вызове '$c_line' произошла ошибка '$result' ($@)\n";
323 }
324 }
325
326 my $c_line = $state->{'convert_binary'}.' -geometry \''.$suffix.'!\' -quality 80 '.$filename_tmp.'.shaved.'.$ext.' '.$filename_tmp.'.'.$suffix.'.'.$ext;
327 my $result = `$c_line`;
328
329 if (length $result > 0) {
330 warn 'Contenido Error: При вызове "'.$c_line.'" произошла ошибка "'.$result.'" ('.$@.")\n";
331 return undef;
332 }
333 @{$IMAGE->{'mini'}{$suffix}}{'filename', 'width', 'height'} = (
334 $filename.'.'.$suffix.'.'.$ext,
335 Image::Size::imgsize($filename_tmp.'.'.$suffix.'.'.$ext),
336 );
337 %{$IMAGE->{'crop'}{$suffix}} = %{$IMAGE->{'mini'}{$suffix}};
338 store($filename.'.'.$suffix.'.'.$ext, $filename_tmp.'.'.$suffix.'.'.$ext);
339 unlink $filename_tmp.'.shaved.'.$ext if -e $filename_tmp.'.shaved.'.$ext;
340 unlink $filename_tmp.'.'.$suffix.'.'.$ext if -e $filename_tmp.'.'.$suffix.'.'.$ext;
341 }
342 if ( @crops ) {
343 if ( !exists $IMAGE->{'mini'}{'filename'} ) {
344 @{$IMAGE->{'mini'}}{'filename', 'width', 'height'} = @{$IMAGE->{'mini'}{$crops[0]}}{'filename', 'width', 'height'};
345 }
346 @{$IMAGE->{'crop'}}{'filename', 'width', 'height'} = @{$IMAGE->{'crop'}{$crops[0]}}{'filename', 'width', 'height'};
347 }
348
349
350 ########## SHRINKS
351 foreach my $suffix (@shrinks) {
352
353 my $c_line = $state->{'convert_binary'}.' -geometry \''.$suffix.'!\' -quality 80 '.$filename_tmp.'.'.$ext.' '.$filename_tmp.'.'.$suffix.'.'.$ext;
354 my $result = `$c_line`;
355
356 if (length $result > 0) {
357 warn 'Contenido Error: При вызове "'.$c_line.'" произошла ошибка "'.$result.'" ('.$@.")\n";
358 return undef;
359 }
360 @{$IMAGE->{'mini'}{$suffix}}{'filename', 'width', 'height'} = (
361 $filename.'.'.$suffix.'.'.$ext,
362 Image::Size::imgsize($filename_tmp.'.'.$suffix.'.'.$ext),
363 );
364 %{$IMAGE->{'shrink'}{$suffix}} = %{$IMAGE->{'mini'}{$suffix}};
365 store($filename.'.'.$suffix.'.'.$ext, $filename_tmp.'.'.$suffix.'.'.$ext);
366 unlink $filename_tmp.'.'.$suffix.'.'.$ext if -e $filename_tmp.'.'.$suffix.'.'.$ext;
367 }
368 if ( @shrinks && !exists $IMAGE->{'mini'}{'filename'} ) {
369 if ( !exists $IMAGE->{'mini'}{'filename'} ) {
370 @{$IMAGE->{'mini'}}{'filename', 'width', 'height'} = @{$IMAGE->{'mini'}{$shrinks[0]}}{'filename', 'width', 'height'};
371 }
372 @{$IMAGE->{'shrink'}}{'filename', 'width', 'height'} = @{$IMAGE->{'shrink'}{$shrinks[0]}}{'filename', 'width', 'height'};
373 }
374
375 unlink $filename_tmp.'.'.$ext if -e $filename_tmp.'.'.$ext;
376 160 ahitrov $IMAGE->{width} = delete $IMAGE->{t_width} if exists $IMAGE->{t_width};
377 $IMAGE->{height} = delete $IMAGE->{t_height} if exists $IMAGE->{t_height};
378 113 ahitrov }
379
380 return $IMAGE;
381 }
382
383 sub remove_image {
384 my $IMAGE = shift;
385
386 if ( ref $IMAGE eq 'HASH' && exists $IMAGE->{filename} ) {
387 remove($IMAGE->{'filename'}) || return;
388 }
389 if ( ref $IMAGE && exists $IMAGE->{mini} && ref $IMAGE->{mini} eq 'HASH' ) {
390 foreach my $val ( values %{$IMAGE->{mini}} ) {
391 if ( ref $val && exists $val->{filename} && $val->{filename} ) {
392 remove($val->{'filename'}) || return;
393 }
394 }
395 }
396 1;
397 }
398
399
400 125 ahitrov sub store_binary {
401 my $input = shift;
402 my (%opts) = @_;
403 my $object = delete $opts{object} || return;
404 my $attr = delete $opts{attr} || return;
405
406 my ($prop) = grep { $_->{attr} eq $attr } $object->structure;
407 return unless ref $prop;
408
409 my $filename = '/binary/'.$object->get_file_name() || return;
410 128 ahitrov if ( $prop->{softrename} ) {
411 my $oid = $object->id || int(rand(10000));
412 my $orig_name = '';
413 if ( ref $input eq 'Apache::Upload' ) {
414 $orig_name = $input->filename();
415 } elsif ( !ref $input ) {
416 $orig_name = $input;
417 }
418 if ( $orig_name ) {
419 if ( $orig_name =~ /\\([^\\]+)$/ ) {
420 $orig_name = $1;
421 } elsif ( $orig_name =~ /\/([^\/]+)$/ ) {
422 $orig_name = $1;
423 }
424 $orig_name =~ s/[\ \t]/_/g;
425 $orig_name = $oid.'_'.$orig_name;
426 $filename =~ s/\/([^\/]+)$//;
427 my $fname = $1;
428 unless ( $orig_name =~ /^[a-zA-Z_\d\.\-\,]+$/ ) {
429 $orig_name = translit( $orig_name );
430 }
431 warn "\n\n\n\n\nNew Name: [$orig_name]\n\n\n\n\n" if $DEBUG;
432 unless ( $orig_name =~ /^[a-zA-Z_\d\.\-\,]+$/ ) {
433 $orig_name = $fname;
434 }
435 $filename .= '/'.$orig_name;
436 $filename =~ s/\.([^\.]+)$//;
437 }
438 }
439
440 125 ahitrov my $filename_tmp = $state->{'tmp_dir'}.'/'.join('_', split('/', $filename));
441
442 my $fh = get_fh($input);
443 return unless ref $fh;
444
445 my $ext;
446 my $size = 1073741824;
447 if ( not ref $input ) {
448 128 ahitrov $ext = $input =~ /\.([^\.]+)$/ ? lc($1) : 'bin';
449 125 ahitrov if ( scheme($input) eq 'file' ) {
450 $size = (stat $fh)[7];
451 }
452 } elsif ( ref $input eq 'Apache::Upload' ) {
453 128 ahitrov $ext = $input->filename() =~ /\.([^\.]+)$/ ? lc($1) : 'bin';
454 125 ahitrov $size = (stat $fh)[7];
455 } elsif ( $opts{filename} ) {
456 128 ahitrov $ext = $opts{filename} =~ /\.([^\.]+)$/ ? lc($1) : 'bin';
457 125 ahitrov }
458 if ( ref $fh eq 'IO::Scalar' ) {
459 $size = length("$fh");
460 }
461 $ext ||= 'bin';
462
463 my $fh_tmp = IO::File->new('>'.$filename_tmp.'.'.$ext) || return;
464 my $buffer;
465
466 $size = sysread $fh, $buffer, $size;
467 syswrite $fh_tmp, $buffer, $size;
468
469 undef $fh_tmp;
470
471 my $BINARY;
472 if ( store($filename.'.'.$ext, $filename_tmp.'.'.$ext) ) {
473 128 ahitrov @{$BINARY}{"filename", "ext", "size"} = (
474 $filename.".".$ext, $ext, $size
475 );
476
477 125 ahitrov unlink $filename_tmp.'.'.$ext if -e $filename_tmp.'.'.$ext;
478 128 ahitrov
479 if ( $ext =~ /(rar|7z|zip|arc|lha|arj|cab)/ ) {
480 $BINARY->{type} = 'archive';
481 } elsif ( $ext =~ /(doc|rtf)/ ) {
482 $BINARY->{type} = 'doc';
483 } elsif ( $ext eq 'xls' ) {
484 $BINARY->{type} = 'xls';
485 } elsif ( $ext =~ /(mdb|ppt)/ ) {
486 $BINARY->{type} = 'msoffice';
487 } elsif ( $ext =~ /(pdf)/ ) {
488 $BINARY->{type} = 'ebook';
489 } elsif ( $ext eq 'psd' ) {
490 $BINARY->{type} = 'psd';
491 } elsif ( $ext =~ /(exe|msi|cab)/ ) {
492 $BINARY->{type} = 'executable';
493 } else {
494 $BINARY->{type} = 'unknown';
495 }
496
497 125 ahitrov }
498
499 return $BINARY;
500 }
501
502 sub remove_binary {
503 my $BINARY = shift;
504
505 if ( ref $BINARY eq 'HASH' && exists $BINARY->{filename} ) {
506 remove($BINARY->{'filename'}) || return;
507 }
508
509 1;
510 }
511
512
513 128 ahitrov sub translit {
514 my $str = shift;
515 my @str = split (//, $str);
516 my $res = '';
517 while ( scalar @str ) {
518 my $alpha = shift @str;
519 if ( exists $translit{$alpha} ) {
520 $res .= $translit{$alpha};
521 } else {
522 $res .= $alpha;
523 }
524 }
525 return $res;
526 }
527
528
529 8 ahitrov@rambler.ru 1;