← 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 11:58:52 2013
Reported on Tue Oct 15 12:01:33 2013

Filename/usr/share/perl5/MIME/Types.pm
StatementsExecuted 26 statements in 1.21ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
111805µs1.01msMIME::Types::::BEGIN@13MIME::Types::BEGIN@13
11115µs42µsMIME::Types::::BEGIN@7MIME::Types::BEGIN@7
11115µs60µsMIME::Types::::BEGIN@190MIME::Types::BEGIN@190
11113µs57µsMIME::Types::::BEGIN@137MIME::Types::BEGIN@137
11111µs63µsMIME::Types::::BEGIN@14MIME::Types::BEGIN@14
11111µs15µsMIME::Types::::BEGIN@11MIME::Types::BEGIN@11
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;
7341µs268µs
# spent 42µs (15+26) within MIME::Types::BEGIN@7 which was called: # once (15µs+26µs) by C4::Letters::BEGIN@23 at line 7
use vars '$VERSION';
# spent 42µs making 1 call to MIME::Types::BEGIN@7 # spent 26µs making 1 call to vars::import
81600ns$VERSION = '1.30';
9
10
11325µs219µs
# spent 15µs (11+4) within MIME::Types::BEGIN@11 which was called: # once (11µs+4µs) by C4::Letters::BEGIN@23 at line 11
use strict;
# spent 15µs making 1 call to MIME::Types::BEGIN@11 # spent 4µs making 1 call to strict::import
12
133123µs11.01ms
# spent 1.01ms (805µs+203µs) within MIME::Types::BEGIN@13 which was called: # once (805µs+203µs) by C4::Letters::BEGIN@23 at line 13
use MIME::Type ();
# spent 1.01ms making 1 call to MIME::Types::BEGIN@13
143638µs2115µs
# spent 63µs (11+52) within MIME::Types::BEGIN@14 which was called: # once (11µs+52µs) by C4::Letters::BEGIN@23 at line 14
use Carp;
# spent 63µs making 1 call to MIME::Types::BEGIN@14 # spent 52µ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
511200nsmy %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
1361900nsrequire Exporter;
1373278µs2100µ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;
190392µs2106µs
# spent 60µs (15+46) within MIME::Types::BEGIN@190 which was called: # once (15µs+46µs) by C4::Letters::BEGIN@23 at line 190
use Carp;
# spent 60µs making 1 call to MIME::Types::BEGIN@190 # spent 46µ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__