| 1 | # Copyrights 1999-2022 by [Mark Overmeer <markov@cpan.org>]. | ||||||||||||||||||||
| 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.03. | ||||||||||||||||||||
| 5 | # This code is part of distribution MIME::Types. Meta-POD processed with | ||||||||||||||||||||
| 6 | # OODoc into POD and HTML manual-pages. See README.md | ||||||||||||||||||||
| 7 | # Copyright Mark Overmeer. Licensed under the same terms as Perl itself. | ||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | package MIME::Type; | ||||||||||||||||||||
| 10 | 6 | ▶ | use vars '$VERSION'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 6 | $VERSION = '2.23'; | |||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 6 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 6 | ▶ | use Carp 'croak'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | #------------------------------------------- | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | use overload | ||||||||||||||||||||
| 23 | 6 | '""' => 'type' | |||||||||||||||||||
| 24 | 6 | ▶ | , cmp => 'cmp'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | #------------------------------------------- | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | 2092 | ▶ | sub new(@) { (bless {}, shift)->init( {@_} ) } | ||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | sub init($) | ||||||||||||||||||||
| 32 | 2092 | ▶ | { my ($self, $args) = @_; | ||||||||||||||||||
|
Subroutine
init: called CC=7 SCAR=19.7
Pod
undocumented
| |||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | my $type = $self->{MT_type} = $args->{type} | ||||||||||||||||||||
| 35 | 2092 | ▶ | or croak "ERROR: Type parameter is obligatory."; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | $self->{MT_simplified} = $args->{simplified} | ||||||||||||||||||||
| 38 | 2092 | ▶ | || $self->simplified($type); | ||||||||||||||||||
|
Condition66%2/3
$args->{'simplified'} || $self->simplified($type)
MC/DC50%1/2
$args->{'simplified'} || $self->simplified($type)
$args->{'simplified'}
$self->simplified($type)
Truth table66%2/3
A || B
A= $args->{'simplified'}B= $self->simplified($type)
| |||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 2092 | ▶ | $self->{MT_extensions} = $args->{extensions} || []; | ||||||||||||||||||
|
Condition100%2/2
$args->{'extensions'} || []
MC/DC100%1/1
$args->{'extensions'} || []
$args->{'extensions'}
Truth table100%2/2
A
A= $args->{'extensions'}
| |||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | $self->{MT_encoding} | ||||||||||||||||||||
| 43 | = $args->{encoding} ? $args->{encoding} | ||||||||||||||||||||
| 44 | 2092 | ▶ | : $self->mediaType eq 'text' ? 'quoted-printable' | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 45 | : 'base64'; | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | $self->{MT_system} = $args->{system} | ||||||||||||||||||||
| 48 | 2092 | ▶ | if defined $args->{system}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 2092 | $self; | |||||||||||||||||||
| 51 | } | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | #------------------------------------------- | ||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 16548 | ▶ | sub type() {shift->{MT_type}} | ||||||||||||||||||
|
Subroutine
type: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | sub simplified(;$) | ||||||||||||||||||||
| 59 | 2179 | ▶ | { my $thing = shift; | ||||||||||||||||||
|
Subroutine
simplified: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||
| 60 | 2179 | ▶ | return $thing->{MT_simplified} unless @_; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | 2124 | my $mime = shift; | |||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 2124 | ▶ | $mime =~ m!^\s*(?:x\-)?([\w.+-]+)/(?:x\-)?([\w.+-]+)\s*$!i ? lc "$1/$2" | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 65 | : $mime eq 'text' ? 'text/plain' # some silly mailers... | ||||||||||||||||||||
| 66 | : undef; | ||||||||||||||||||||
| 67 | } | ||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | 4132 | ▶ | sub extensions() { @{shift->{MT_extensions}} } | ||||||||||||||||||
|
Subroutine
extensions: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 71 | 4099 | ▶ | sub encoding() {shift->{MT_encoding}} | ||||||||||||||||||
|
Subroutine
encoding: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 72 | 0 | ▶ | sub system() {shift->{MT_system}} | ||||||||||||||||||
|
Subroutine
system: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | #------------------------------------------- | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | 1994 | ▶ | sub mediaType() {shift->{MT_simplified} =~ m!^([\w.-]+)/! ? $1 : undef} | ||||||||||||||||||
|
Subroutine
mediaType: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||
| 78 | 2 | ▶ | sub mainType() {shift->mediaType} # Backwards compatibility | ||||||||||||||||||
|
Subroutine
mainType: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | 2 | ▶ | sub subType() {shift->{MT_simplified} =~ m!/([\w+.-]+)$! ? $1 : undef} | ||||||||||||||||||
|
Subroutine
subType: called CC=2 SCAR=7.6
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | 8 | ▶ | sub isRegistered() { lc shift->{MT_type} !~ m{^x\-|/x\-} } | ||||||||||||||||||
|
Subroutine
isRegistered: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | # http://tools.ietf.org/html/rfc4288#section-3 | ||||||||||||||||||||
| 88 | 4 | ▶ | sub isVendor() {shift->{MT_simplified} =~ m!/vnd\.!} | ||||||||||||||||||
|
Subroutine
isVendor: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 89 | 4 | ▶ | sub isPersonal() {shift->{MT_simplified} =~ m!/prs\.!} | ||||||||||||||||||
|
Subroutine
isPersonal: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 90 | 4 | ▶ | sub isExperimental() {shift->{MT_simplified} =~ m!/x\.! } | ||||||||||||||||||
|
Subroutine
isExperimental: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | 4 | ▶ | sub isBinary() { shift->{MT_encoding} eq 'base64' } | ||||||||||||||||||
|
Subroutine
isBinary: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 94 | 4 | ▶ | sub isText() { shift->{MT_encoding} ne 'base64' } | ||||||||||||||||||
|
Subroutine
isText: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 95 | 6 | *isAscii = \&isText; | |||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | # simplified names only! | ||||||||||||||||||||
| 99 | 6 | my %sigs = map +($_ => 1), | |||||||||||||||||||
| 100 | qw(application/pgp-keys application/pgp application/pgp-signature | ||||||||||||||||||||
| 101 | application/pkcs10 application/pkcs7-mime application/pkcs7-signature | ||||||||||||||||||||
| 102 | text/vCard); | ||||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | 0 | ▶ | sub isSignature() { $sigs{shift->{MT_simplified}} } | ||||||||||||||||||
|
Subroutine
isSignature: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | sub cmp($) | ||||||||||||||||||||
| 108 | 37 | ▶ | { my ($self, $other) = @_; | ||||||||||||||||||
|
Subroutine
cmp: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | 37 | ▶ | my $type = ref $other | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 111 | ? $other->simplified | ||||||||||||||||||||
| 112 | : (ref $self)->simplified($other); | ||||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | 37 | $self->simplified cmp $type; | |||||||||||||||||||
| 115 | } | ||||||||||||||||||||
| 116 | 19 | ▶ | sub equals($) { $_[0]->cmp($_[1])==0 } | ||||||||||||||||||
|
Subroutine
equals: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | 6 | 1; | |||||||||||||||||||