|
Revision 856
(checked in by miyagawa, 6 years ago)
|
merge from trunk to plagger-server for Enclosures support and such. Sorry for the big commit
|
| Line | |
|---|
| 1 |
package Plagger::Enclosure; |
|---|
| 2 |
use strict; |
|---|
| 3 |
|
|---|
| 4 |
use base qw( Class::Accessor::Fast ); |
|---|
| 5 |
__PACKAGE__->mk_accessors(qw( length type local_path is_inline )); |
|---|
| 6 |
|
|---|
| 7 |
use Plagger::Util; |
|---|
| 8 |
use URI; |
|---|
| 9 |
|
|---|
| 10 |
sub url { |
|---|
| 11 |
my $self = shift; |
|---|
| 12 |
if (@_) { |
|---|
| 13 |
$self->{url} = URI->new($_[0]); |
|---|
| 14 |
} |
|---|
| 15 |
$self->{url}; |
|---|
| 16 |
} |
|---|
| 17 |
|
|---|
| 18 |
sub auto_set_type { |
|---|
| 19 |
my($self, $type) = @_; |
|---|
| 20 |
|
|---|
| 21 |
if (defined $type) { |
|---|
| 22 |
return $self->type($type); |
|---|
| 23 |
} |
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
my $mime = Plagger::Util::mime_type_of($self->url); |
|---|
| 27 |
$self->type($mime->type) if $mime; |
|---|
| 28 |
} |
|---|
| 29 |
|
|---|
| 30 |
sub media_type { |
|---|
| 31 |
my $self = shift; |
|---|
| 32 |
( split '/', $self->type )[0] || 'unknown'; |
|---|
| 33 |
} |
|---|
| 34 |
|
|---|
| 35 |
sub sub_type { |
|---|
| 36 |
my $self = shift; |
|---|
| 37 |
( split '/', $self->type )[1] || 'unknown'; |
|---|
| 38 |
} |
|---|
| 39 |
|
|---|
| 40 |
sub filename { |
|---|
| 41 |
my $self = shift; |
|---|
| 42 |
if (@_) { |
|---|
| 43 |
$self->{filename} = shift; |
|---|
| 44 |
} |
|---|
| 45 |
$self->{filename} || (split '/', $self->url->path)[-1]; |
|---|
| 46 |
} |
|---|
| 47 |
|
|---|
| 48 |
1; |
|---|
| 49 |
|
|---|