diff options
author | Karl Berry <karl@freefriends.org> | 2020-03-07 22:52:33 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2020-03-07 22:52:33 +0000 |
commit | 11c6e5fc65f26ba5219997d19707b998a9abf26d (patch) | |
tree | a1dc8073a679611d3f09c01eda006cc3f6f846b1 /Master/tlpkg/tlperl/site/lib/LWP/MediaTypes.pm | |
parent | a6593bd4f2eb12ae25540de026f7f9ebcf230a2f (diff) |
tl20 perl 5.30.1 for Windows, from Siep
git-svn-id: svn://tug.org/texlive/trunk@54166 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/tlpkg/tlperl/site/lib/LWP/MediaTypes.pm')
-rw-r--r-- | Master/tlpkg/tlperl/site/lib/LWP/MediaTypes.pm | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/Master/tlpkg/tlperl/site/lib/LWP/MediaTypes.pm b/Master/tlpkg/tlperl/site/lib/LWP/MediaTypes.pm index 8c2a8aee334..22d00e3391b 100644 --- a/Master/tlpkg/tlperl/site/lib/LWP/MediaTypes.pm +++ b/Master/tlpkg/tlperl/site/lib/LWP/MediaTypes.pm @@ -4,9 +4,11 @@ require Exporter; @ISA = qw(Exporter); @EXPORT = qw(guess_media_type media_suffix); @EXPORT_OK = qw(add_type add_encoding read_media_types); -$VERSION = "6.02"; +our $VERSION = '6.04'; use strict; +use Scalar::Util qw(blessed); +use Carp qw(croak); # note: These hashes will also be filled with the entries found in # the 'media.types' file. @@ -47,10 +49,17 @@ sub guess_media_type return undef unless defined $file; my $fullname; - if (ref($file)) { - # assume URI object - $file = $file->path; - #XXX should handle non http:, file: or ftp: URIs differently + if (ref $file) { + croak("Unable to determine filetype on unblessed refs") unless blessed($file); + if ($file->can('path')) { + $file = $file->path; + } + elsif ($file->can('filename')) { + $fullname = $file->filename; + } + else { + $fullname = "" . $file; + } } else { $fullname = $file; # enable peek at actual file @@ -124,7 +133,7 @@ sub media_suffix { } -sub file_exts +sub file_exts { require File::Basename; my @parts = reverse split(/\./, File::Basename::basename($_[0])); @@ -133,7 +142,7 @@ sub file_exts } -sub add_type +sub add_type { my($type, @exts) = @_; for my $ext (@exts) { @@ -154,7 +163,7 @@ sub add_encoding } -sub read_media_types +sub read_media_types { my(@files) = @_; @@ -214,9 +223,12 @@ The following functions are exported by default: =item guess_media_type( $uri ) -=item guess_media_type( $filename_or_uri, $header_to_modify ) +=item guess_media_type( $filename_or_object, $header_to_modify ) -This function tries to guess media type and encoding for a file or a URI. +This function tries to guess media type and encoding for a file or objects that +support the a C<path> or C<filename> method, eg, L<URI> or L<File::Temp> objects. +When an object does not support either method, it will be stringified to +determine the filename. It returns the content type, which is a string like C<"text/html">. In array context it also returns any content encodings applied (in the order used to encode the file). You can pass a URI object |