root/trunk/plagger/lib/Plagger/Enclosure.pm

Revision 749 (checked in by miyagawa, 14 years ago)
  • New plugin Filter::FindEnclosures? to auto-discover enclosures
  • New plugin Filter:::HEADEnclosureMetadata to get metadata from enclosures with HEAD requests
  • Added is_inline attribute to Plagger::Enclosure. Fixes #230
  • Publish::Feed: Only publish enclosures with URL set and no is_line flag. Fixes #234
  • Added Plagger::Util::mime_type_of
  • Added flv/m4a to known MIME types list of MIME::Types
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     # set MIME type via URL extension
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
Note: See TracBrowser for help on using the browser.