Filename | /usr/share/perl5/MIME/Type.pm |
Statements | Executed 15 statements in 760µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 25µs | 64µs | BEGIN@6 | MIME::Type::
1 | 1 | 1 | 13µs | 74µs | BEGIN@12 | MIME::Type::
1 | 1 | 1 | 13µs | 78µs | BEGIN@18 | MIME::Type::
1 | 1 | 1 | 10µs | 14µs | BEGIN@10 | MIME::Type::
0 | 0 | 0 | 0s | 0s | encoding | MIME::Type::
0 | 0 | 0 | 0s | 0s | equals | MIME::Type::
0 | 0 | 0 | 0s | 0s | extensions | MIME::Type::
0 | 0 | 0 | 0s | 0s | init | MIME::Type::
0 | 0 | 0 | 0s | 0s | isAscii | MIME::Type::
0 | 0 | 0 | 0s | 0s | isBinary | MIME::Type::
0 | 0 | 0 | 0s | 0s | isRegistered | MIME::Type::
0 | 0 | 0 | 0s | 0s | isSignature | MIME::Type::
0 | 0 | 0 | 0s | 0s | mainType | MIME::Type::
0 | 0 | 0 | 0s | 0s | mediaType | MIME::Type::
0 | 0 | 0 | 0s | 0s | new | MIME::Type::
0 | 0 | 0 | 0s | 0s | simplified | MIME::Type::
0 | 0 | 0 | 0s | 0s | subType | MIME::Type::
0 | 0 | 0 | 0s | 0s | system | MIME::Type::
0 | 0 | 0 | 0s | 0s | type | MIME::Type::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # Copyrights 1999,2001-2010 by Mark Overmeer. | ||||
2 | # For other contributors see ChangeLog. | ||||
3 | # See the manual pages for details on the licensing terms. | ||||
4 | # Pod stripped from pm file by OODoc 1.06. | ||||
5 | package MIME::Type; | ||||
6 | 3 | 44µs | 2 | 103µs | # spent 64µs (25+39) within MIME::Type::BEGIN@6 which was called:
# once (25µs+39µs) by MIME::Types::BEGIN@13 at line 6 # spent 64µs making 1 call to MIME::Type::BEGIN@6
# spent 39µs making 1 call to vars::import |
7 | 1 | 800ns | $VERSION = '1.30'; | ||
8 | |||||
9 | |||||
10 | 3 | 27µs | 2 | 18µs | # spent 14µs (10+4) within MIME::Type::BEGIN@10 which was called:
# once (10µs+4µs) by MIME::Types::BEGIN@13 at line 10 # spent 14µs making 1 call to MIME::Type::BEGIN@10
# spent 4µs making 1 call to strict::import |
11 | |||||
12 | 3 | 41µs | 2 | 135µs | # spent 74µs (13+61) within MIME::Type::BEGIN@12 which was called:
# once (13µs+61µs) by MIME::Types::BEGIN@13 at line 12 # spent 74µs making 1 call to MIME::Type::BEGIN@12
# spent 61µs making 1 call to Exporter::import |
13 | |||||
14 | |||||
15 | #------------------------------------------- | ||||
16 | |||||
17 | |||||
18 | 1 | 9µs | 1 | 64µs | # spent 78µs (13+64) within MIME::Type::BEGIN@18 which was called:
# once (13µs+64µs) by MIME::Types::BEGIN@13 at line 20 # spent 64µs making 1 call to overload::import |
19 | , cmp => 'equals' | ||||
20 | 2 | 622µs | 1 | 78µs | ; # spent 78µs making 1 call to MIME::Type::BEGIN@18 |
21 | |||||
22 | #------------------------------------------- | ||||
23 | |||||
24 | |||||
25 | sub new(@) { (bless {}, shift)->init( {@_} ) } | ||||
26 | |||||
27 | sub init($) | ||||
28 | { my ($self, $args) = @_; | ||||
29 | |||||
30 | $self->{MT_type} = $args->{type} | ||||
31 | or croak "ERROR: Type parameter is obligatory."; | ||||
32 | |||||
33 | $self->{MT_simplified} = $args->{simplified} | ||||
34 | || ref($self)->simplified($args->{type}); | ||||
35 | |||||
36 | $self->{MT_extensions} = $args->{extensions} || []; | ||||
37 | |||||
38 | $self->{MT_encoding} | ||||
39 | = $args->{encoding} ? $args->{encoding} | ||||
40 | : $self->mediaType eq 'text' ? 'quoted-printable' | ||||
41 | : 'base64'; | ||||
42 | |||||
43 | $self->{MT_system} = $args->{system} | ||||
44 | if defined $args->{system}; | ||||
45 | |||||
46 | $self; | ||||
47 | } | ||||
48 | |||||
49 | #------------------------------------------- | ||||
50 | |||||
51 | |||||
52 | sub type() {shift->{MT_type}} | ||||
53 | |||||
54 | #------------------------------------------- | ||||
55 | |||||
56 | |||||
57 | sub simplified(;$) | ||||
58 | { my $thing = shift; | ||||
59 | return $thing->{MT_simplified} unless @_; | ||||
60 | |||||
61 | my $mime = shift; | ||||
62 | |||||
63 | $mime =~ m!^\s*(?:x\-)?([\w.+-]+)/(?:x\-)?([\w.+-]+)\s*$!i ? lc "$1/$2" | ||||
64 | : $mime =~ m!text! ? "text/plain" # some silly mailers... | ||||
65 | : undef; | ||||
66 | } | ||||
67 | |||||
68 | #------------------------------------------- | ||||
69 | |||||
70 | |||||
71 | sub extensions() { @{shift->{MT_extensions}} } | ||||
72 | |||||
73 | #------------------------------------------- | ||||
74 | |||||
75 | |||||
76 | sub encoding() {shift->{MT_encoding}} | ||||
77 | |||||
78 | #------------------------------------------- | ||||
79 | |||||
80 | |||||
81 | sub system() {shift->{MT_system}} | ||||
82 | |||||
83 | #------------------------------------------- | ||||
84 | |||||
85 | |||||
86 | sub mediaType() {shift->{MT_simplified} =~ m!^([\w-]+)/! ? $1 : undef} | ||||
87 | |||||
88 | sub mainType() {shift->mediaType} # Backwards compatibility | ||||
89 | |||||
90 | #------------------------------------------- | ||||
91 | |||||
92 | |||||
93 | sub subType() {shift->{MT_simplified} =~ m!/([\w-]+)$! ? $1 : undef} | ||||
94 | |||||
95 | #------------------------------------------- | ||||
96 | |||||
97 | |||||
98 | sub isRegistered() | ||||
99 | { local $_ = shift->{MT_type}; | ||||
100 | not (m/^[xX]\-/ || m!/[xX]\-!); | ||||
101 | } | ||||
102 | |||||
103 | |||||
104 | #------------------------------------------- | ||||
105 | |||||
106 | |||||
107 | sub isBinary() { shift->{MT_encoding} eq 'base64' } | ||||
108 | |||||
109 | #------------------------------------------- | ||||
110 | |||||
111 | |||||
112 | sub isAscii() { shift->{MT_encoding} ne 'base64' } | ||||
113 | |||||
114 | #------------------------------------------- | ||||
115 | |||||
116 | |||||
117 | # simplified names only! | ||||
118 | 1 | 11µs | my %sigs = map { ($_ => 1) } | ||
119 | qw(application/pgp-keys application/pgp application/pgp-signature | ||||
120 | application/pkcs10 application/pkcs7-mime application/pkcs7-signature | ||||
121 | text/vCard); | ||||
122 | |||||
123 | sub isSignature() { $sigs{shift->{MT_simplified}} } | ||||
124 | |||||
125 | #------------------------------------------- | ||||
126 | |||||
127 | |||||
128 | sub equals($) | ||||
129 | { my ($self, $other) = @_; | ||||
130 | |||||
131 | my $type = ref $other | ||||
132 | ? $other->simplified | ||||
133 | : (ref $self)->simplified($other); | ||||
134 | |||||
135 | $self->simplified cmp $type; | ||||
136 | } | ||||
137 | |||||
138 | 1 | 5µs | 1; |