line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WordPress::Base::MediaObject; |
2
|
2
|
|
|
2
|
|
41290
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
63
|
|
3
|
2
|
|
|
2
|
|
8
|
use vars qw($VERSION @ISA @EXPORT_OK %EXPORT_TAGS); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
143
|
|
4
|
2
|
|
|
2
|
|
11
|
use Exporter; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
838
|
|
5
|
|
|
|
|
|
|
@ISA = qw/Exporter/; |
6
|
|
|
|
|
|
|
$VERSION = sprintf "%d.%02d", q$Revision: 1.2 $ =~ /(\d+)/g; |
7
|
|
|
|
|
|
|
@EXPORT_OK = qw(get_mime_type get_file_bits get_file_name abs_path_to_media_object_data); |
8
|
|
|
|
|
|
|
%EXPORT_TAGS = ( 'all' => \@EXPORT_OK ); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# optionally we can request other files to get mime on |
11
|
|
|
|
|
|
|
sub get_mime_type { |
12
|
2
|
|
|
2
|
1
|
15
|
my $abs = shift; |
13
|
2
|
50
|
|
|
|
7
|
$abs or confess('missing arg'); |
14
|
2
|
|
|
|
|
1756
|
require File::Type; |
15
|
2
|
|
|
|
|
47723
|
my $ft = new File::Type; |
16
|
2
|
50
|
|
|
|
35
|
my $type = $ft->mime_type($abs) or die('missing mime'); |
17
|
2
|
|
|
|
|
2825
|
return $type; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub get_file_bits { |
21
|
2
|
|
|
2
|
1
|
8
|
my $abs_path = shift; |
22
|
2
|
50
|
|
|
|
10
|
$abs_path or die; |
23
|
|
|
|
|
|
|
# from http://search.cpan.org/~gaas/MIME-Base64-3.07/Base64.pm |
24
|
2
|
|
|
|
|
1284
|
require MIME::Base64; |
25
|
|
|
|
|
|
|
|
26
|
2
|
50
|
|
|
|
20978
|
open(FILE, $abs_path) or die($!); |
27
|
2
|
|
|
|
|
6
|
my $bits; |
28
|
|
|
|
|
|
|
my $buffer; |
29
|
2
|
|
|
|
|
51
|
while( read(FILE, $buffer, (60*57)) ) { |
30
|
12
|
|
|
|
|
145
|
$bits.= $buffer; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
2
|
|
|
|
|
73
|
return $bits; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub get_file_name { |
37
|
2
|
|
|
2
|
1
|
5
|
my $string = shift; |
38
|
2
|
50
|
|
|
|
7
|
$string or croak('missing path'); |
39
|
|
|
|
|
|
|
|
40
|
2
|
|
|
|
|
19
|
$string=~s/^.+\/+|\/+$//g; |
41
|
2
|
|
|
|
|
12
|
return $string; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub abs_path_to_media_object_data { |
46
|
1
|
|
|
1
|
1
|
5
|
my $abs_path = shift; |
47
|
1
|
50
|
|
|
|
8
|
$abs_path or croak('missing path arg'); |
48
|
|
|
|
|
|
|
|
49
|
1
|
|
|
|
|
4
|
my $struct ={ |
50
|
|
|
|
|
|
|
name => get_file_name($abs_path), |
51
|
|
|
|
|
|
|
type => get_mime_type($abs_path), |
52
|
|
|
|
|
|
|
bits => get_file_bits($abs_path), |
53
|
|
|
|
|
|
|
}; |
54
|
|
|
|
|
|
|
|
55
|
1
|
|
|
|
|
6
|
return $struct; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
__END__ |