← Index
NYTProf Performance Profile   « block view • line view • sub view »
For /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
  Run on Tue Oct 15 17:10:45 2013
Reported on Tue Oct 15 17:11:26 2013

Filename/usr/share/perl5/MIME/Types.pm
StatementsExecuted 26 statements in 1.29ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
111854µs1.08msMIME::Types::::BEGIN@13MIME::Types::BEGIN@13
11127µs39µsMIME::Types::::BEGIN@11MIME::Types::BEGIN@11
11124µs68µsMIME::Types::::BEGIN@7MIME::Types::BEGIN@7
11115µs58µsMIME::Types::::BEGIN@190MIME::Types::BEGIN@190
11113µs57µsMIME::Types::::BEGIN@137MIME::Types::BEGIN@137
11113µs100µsMIME::Types::::BEGIN@14MIME::Types::BEGIN@14
0000s0sMIME::Types::::addTypeMIME::Types::addType
0000s0sMIME::Types::::by_mediatypeMIME::Types::by_mediatype
0000s0sMIME::Types::::by_suffixMIME::Types::by_suffix
0000s0sMIME::Types::::create_type_indexMIME::Types::create_type_index
0000s0sMIME::Types::::extensionsMIME::Types::extensions
0000s0sMIME::Types::::import_mime_typesMIME::Types::import_mime_types
0000s0sMIME::Types::::initMIME::Types::init
0000s0sMIME::Types::::mimeTypeOfMIME::Types::mimeTypeOf
0000s0sMIME::Types::::newMIME::Types::new
0000s0sMIME::Types::::typeMIME::Types::type
0000s0sMIME::Types::::typesMIME::Types::types
Call graph for these subroutines as a Graphviz dot language file.
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
6package MIME::Types;
7350µs2111µs
# spent 68µs (24+43) within MIME::Types::BEGIN@7 which was called: # once (24µs+43µs) by C4::Letters::BEGIN@23 at line 7
use vars '$VERSION';
# spent 68µs making 1 call to MIME::Types::BEGIN@7 # spent 43µs making 1 call to vars::import
81800ns$VERSION = '1.30';
9
10
11343µs251µs
# spent 39µs (27+12) within MIME::Types::BEGIN@11 which was called: # once (27µs+12µs) by C4::Letters::BEGIN@23 at line 11
use strict;
# spent 39µs making 1 call to MIME::Types::BEGIN@11 # spent 12µs making 1 call to strict::import
12
133173µs11.08ms
# spent 1.08ms (854µs+230µs) within MIME::Types::BEGIN@13 which was called: # once (854µs+230µs) by C4::Letters::BEGIN@23 at line 13
use MIME::Type ();
# spent 1.08ms making 1 call to MIME::Types::BEGIN@13
143590µs2187µs
# spent 100µs (13+87) within MIME::Types::BEGIN@14 which was called: # once (13µs+87µs) by C4::Letters::BEGIN@23 at line 14
use Carp;
# spent 100µs making 1 call to MIME::Types::BEGIN@14 # spent 87µs making 1 call to Exporter::import
15
16
171300nsmy %list;
18sub new(@) { (bless {}, shift)->init( {@_} ) }
19
20sub init($)
21{ my ($self, $args) = @_;
22
23 unless(keys %list) # already read
24 { local $_;
25 local $/ = "\n";
26
27 while(<DATA>)
28 { chomp;
29 next if !length $_ or substr($_, 0, 1) eq '#';
30
31 my $os = s/^(\w+)\:// ? qr/$1/i : undef;
32 my ($type, $extensions, $encoding) = split /\;/;
33
34 next if $args->{only_complete} && ! $extensions;
35 my $extent = $extensions ? [ split /\,/, $extensions ] : undef;
36
37 my $simplified = MIME::Type->simplified($type);
38 push @{$list{$simplified}}, MIME::Type->new
39 ( type => $type
40 , extensions => $extent
41 , encoding => $encoding
42 , system => $os
43 );
44 }
45 close DATA;
46 }
47
48 $self;
49}
50
511100nsmy %type_index;
52sub create_type_index()
53{ my $self = shift;
54
55 my @os_specific;
56 while(my ($simple, $definitions) = each %list)
57 { foreach my $def (@$definitions)
58 { if(defined(my $sys = $def->system))
59 { # OS specific definitions will overrule the
60 # unspecific definitions, so must be postponed till
61 # the end.
62 push @os_specific, $def if $^O =~ $sys;
63 }
64 else
65 { $type_index{$_} = $def foreach $def->extensions;
66 }
67 }
68 }
69
70 foreach my $def (@os_specific)
71 { $type_index{$_} = $def foreach $def->extensions;
72 }
73
74 $self;
75}
76
77#-------------------------------------------
78
79
80sub type($)
81{ my $mime = MIME::Type->simplified($_[1]) or return;
82 return () unless exists $list{$mime};
83 wantarray ? @{$list{$mime}} : $list{$mime}[0];
84}
85
86#-------------------------------------------
87
88
89sub mimeTypeOf($)
90{ my ($self, $name) = @_;
91 $self->create_type_index unless keys %type_index;
92 $name =~ s/.*\.//;
93 $type_index{lc $name};
94}
95
96#-------------------------------------------
97
98
99sub addType(@)
100{ my $self = shift;
101
102 foreach my $type (@_)
103 { my $simplified = $type->simplified;
104 push @{$list{$simplified}}, $type;
105 }
106
107 %type_index = ();
108 $self;
109}
110
111#-------------------------------------------
112
113
114sub types
115{ my $self = shift;
116
117 $self->create_type_index unless keys %type_index;
118 return values %type_index;
119}
120
121#-------------------------------------------
122
123
124sub extensions
125{ my $self = shift;
126 $self->create_type_index unless keys %type_index;
127
128 return keys %type_index;
129}
130
131#-------------------------------------------
132
133
134#-------------------------------------------
135
13612µsrequire Exporter;
1373356µs2102µs
# spent 57µs (13+44) within MIME::Types::BEGIN@137 which was called: # once (13µs+44µs) by C4::Letters::BEGIN@23 at line 137
use vars qw/@ISA @EXPORT_OK/;
# spent 57µs making 1 call to MIME::Types::BEGIN@137 # spent 44µs making 1 call to vars::import
138110µs@ISA = qw(Exporter);
13911µs@EXPORT_OK = qw(by_suffix by_mediatype import_mime_types);
140
141#-------------------------------------------
142
143
1441200nsmy $mime_types;
145
146sub by_suffix($)
147{ my $filename = shift;
148 $mime_types ||= MIME::Types->new;
149 my $mime = $mime_types->mimeTypeOf($filename);
150
151 my @data = defined $mime ? ($mime->type, $mime->encoding) : ('','');
152 wantarray ? @data : \@data;
153}
154
155#-------------------------------------------
156
157
158sub by_mediatype($)
159{ my $type = shift;
160 my @found;
161
162 %list or init {};
163
164 if(index($type, '/') >= 0)
165 { my $simplified = MIME::Type->simplified($type);
166 my $mime = $list{$simplified};
167 push @found, @$mime if defined $mime;
168 }
169 else
170 { my $mime = ref $type ? $type : qr/$type/i;
171 @found = map {@{$list{$_}}}
172 grep {$_ =~ $mime}
173 keys %list;
174 }
175
176 my @data;
177 foreach my $mime (@found)
178 { push @data, map { [$_, $mime->type, $mime->encoding] }
179 $mime->extensions;
180 }
181
182 wantarray ? @data : \@data;
183}
184
185#-------------------------------------------
186
187
188sub import_mime_types($)
189{ my $filename = shift;
190361µs2102µs
# spent 58µs (15+43) within MIME::Types::BEGIN@190 which was called: # once (15µs+43µs) by C4::Letters::BEGIN@23 at line 190
use Carp;
# spent 58µs making 1 call to MIME::Types::BEGIN@190 # spent 44µs making 1 call to Exporter::import
191 croak <<'CROAK';
192import_mime_types is not supported anymore: if you have types to add
193please send them to the author.
194CROAK
195}
196
19715µs1;
198
199#-------------------------------------------
200# Internet media type registry is at
201# http://www.iana.org/assignments/media-types/
202# Another list can be found at: http://ftyps.com
203
204__DATA__