| Filename | /usr/share/perl5/MIME/Type.pm |
| Statements | Executed 12 statements in 1.03ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 11µs | 28µs | MIME::Type::BEGIN@6 |
| 1 | 1 | 1 | 10µs | 40µs | MIME::Type::BEGIN@19 |
| 1 | 1 | 1 | 9µs | 42µs | MIME::Type::BEGIN@12 |
| 1 | 1 | 1 | 6µs | 15µs | MIME::Type::BEGIN@10 |
| 0 | 0 | 0 | 0s | 0s | MIME::Type::cmp |
| 0 | 0 | 0 | 0s | 0s | MIME::Type::encoding |
| 0 | 0 | 0 | 0s | 0s | MIME::Type::equals |
| 0 | 0 | 0 | 0s | 0s | MIME::Type::extensions |
| 0 | 0 | 0 | 0s | 0s | MIME::Type::init |
| 0 | 0 | 0 | 0s | 0s | MIME::Type::isBinary |
| 0 | 0 | 0 | 0s | 0s | MIME::Type::isExperimental |
| 0 | 0 | 0 | 0s | 0s | MIME::Type::isPersonal |
| 0 | 0 | 0 | 0s | 0s | MIME::Type::isRegistered |
| 0 | 0 | 0 | 0s | 0s | MIME::Type::isSignature |
| 0 | 0 | 0 | 0s | 0s | MIME::Type::isText |
| 0 | 0 | 0 | 0s | 0s | MIME::Type::isVendor |
| 0 | 0 | 0 | 0s | 0s | MIME::Type::mainType |
| 0 | 0 | 0 | 0s | 0s | MIME::Type::mediaType |
| 0 | 0 | 0 | 0s | 0s | MIME::Type::new |
| 0 | 0 | 0 | 0s | 0s | MIME::Type::simplified |
| 0 | 0 | 0 | 0s | 0s | MIME::Type::subType |
| 0 | 0 | 0 | 0s | 0s | MIME::Type::system |
| 0 | 0 | 0 | 0s | 0s | MIME::Type::type |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | # Copyrights 1999,2001-2014 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 2.01. | ||||
| 5 | package MIME::Type; | ||||
| 6 | 2 | 30µs | 2 | 45µs | # spent 28µs (11+17) within MIME::Type::BEGIN@6 which was called:
# once (11µs+17µs) by MIME::Types::BEGIN@13 at line 6 # spent 28µs making 1 call to MIME::Type::BEGIN@6
# spent 17µs making 1 call to vars::import |
| 7 | 1 | 500ns | $VERSION = '2.09'; | ||
| 8 | |||||
| 9 | |||||
| 10 | 2 | 21µs | 2 | 24µs | # spent 15µs (6+9) within MIME::Type::BEGIN@10 which was called:
# once (6µs+9µs) by MIME::Types::BEGIN@13 at line 10 # spent 15µs making 1 call to MIME::Type::BEGIN@10
# spent 9µs making 1 call to strict::import |
| 11 | |||||
| 12 | 2 | 37µs | 2 | 76µs | # spent 42µs (9+33) within MIME::Type::BEGIN@12 which was called:
# once (9µs+33µs) by MIME::Types::BEGIN@13 at line 12 # spent 42µs making 1 call to MIME::Type::BEGIN@12
# spent 33µs making 1 call to Exporter::import |
| 13 | |||||
| 14 | |||||
| 15 | #------------------------------------------- | ||||
| 16 | |||||
| 17 | |||||
| 18 | use overload | ||||
| 19 | 1 | 6µs | 1 | 30µs | # spent 40µs (10+30) within MIME::Type::BEGIN@19 which was called:
# once (10µs+30µs) by MIME::Types::BEGIN@13 at line 20 # spent 30µs making 1 call to overload::import |
| 20 | 1 | 921µs | 1 | 40µs | , cmp => 'cmp'; # spent 40µs making 1 call to MIME::Type::BEGIN@19 |
| 21 | |||||
| 22 | #------------------------------------------- | ||||
| 23 | |||||
| 24 | |||||
| 25 | sub new(@) { (bless {}, shift)->init( {@_} ) } | ||||
| 26 | |||||
| 27 | sub init($) | ||||
| 28 | { my ($self, $args) = @_; | ||||
| 29 | |||||
| 30 | my $type = $self->{MT_type} = $args->{type} | ||||
| 31 | or croak "ERROR: Type parameter is obligatory."; | ||||
| 32 | |||||
| 33 | $self->{MT_simplified} = $args->{simplified} | ||||
| 34 | || $self->simplified($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 | sub type() {shift->{MT_type}} | ||||
| 52 | |||||
| 53 | |||||
| 54 | sub simplified(;$) | ||||
| 55 | { my $thing = shift; | ||||
| 56 | return $thing->{MT_simplified} unless @_; | ||||
| 57 | |||||
| 58 | my $mime = shift; | ||||
| 59 | |||||
| 60 | $mime =~ m!^\s*(?:x\-)?([\w.+-]+)/(?:x\-)?([\w.+-]+)\s*$!i ? lc "$1/$2" | ||||
| 61 | : $mime eq 'text' ? 'text/plain' # some silly mailers... | ||||
| 62 | : undef; | ||||
| 63 | } | ||||
| 64 | |||||
| 65 | |||||
| 66 | sub extensions() { @{shift->{MT_extensions}} } | ||||
| 67 | sub encoding() {shift->{MT_encoding}} | ||||
| 68 | sub system() {shift->{MT_system}} | ||||
| 69 | |||||
| 70 | #------------------------------------------- | ||||
| 71 | |||||
| 72 | |||||
| 73 | sub mediaType() {shift->{MT_simplified} =~ m!^([\w.-]+)/! ? $1 : undef} | ||||
| 74 | sub mainType() {shift->mediaType} # Backwards compatibility | ||||
| 75 | |||||
| 76 | |||||
| 77 | sub subType() {shift->{MT_simplified} =~ m!/([\w+.-]+)$! ? $1 : undef} | ||||
| 78 | |||||
| 79 | |||||
| 80 | sub isRegistered() { lc shift->{MT_type} !~ m{^x\-|/x\-} } | ||||
| 81 | |||||
| 82 | |||||
| 83 | # http://tools.ietf.org/html/rfc4288#section-3 | ||||
| 84 | sub isVendor() {shift->{MT_simplified} =~ m!/vnd\.!} | ||||
| 85 | sub isPersonal() {shift->{MT_simplified} =~ m!/prs\.!} | ||||
| 86 | sub isExperimental() {shift->{MT_simplified} =~ m!/x\.! } | ||||
| 87 | |||||
| 88 | |||||
| 89 | sub isBinary() { shift->{MT_encoding} eq 'base64' } | ||||
| 90 | sub isText() { shift->{MT_encoding} ne 'base64' } | ||||
| 91 | 1 | 900ns | *isAscii = \&isText; | ||
| 92 | |||||
| 93 | |||||
| 94 | # simplified names only! | ||||
| 95 | 1 | 8µs | my %sigs = map +($_ => 1), | ||
| 96 | qw(application/pgp-keys application/pgp application/pgp-signature | ||||
| 97 | application/pkcs10 application/pkcs7-mime application/pkcs7-signature | ||||
| 98 | text/vCard); | ||||
| 99 | |||||
| 100 | sub isSignature() { $sigs{shift->{MT_simplified}} } | ||||
| 101 | |||||
| 102 | |||||
| 103 | sub cmp($) | ||||
| 104 | { my ($self, $other) = @_; | ||||
| 105 | |||||
| 106 | my $type = ref $other | ||||
| 107 | ? $other->simplified | ||||
| 108 | : (ref $self)->simplified($other); | ||||
| 109 | |||||
| 110 | $self->simplified cmp $type; | ||||
| 111 | } | ||||
| 112 | sub equals($) { $_[0]->cmp($_[1])==0 } | ||||
| 113 | |||||
| 114 | 1 | 4µs | 1; |