| 1 | package Net::PMP::Profile::Media; | ||
| 2 | use Moose; | ||
| 3 | extends 'Net::PMP::Profile'; | ||
| 4 | use Net::PMP::Profile::MediaEnclosure; | ||
| 5 | use Media::Type::Simple; | ||
| 6 | use Try::Tiny; | ||
| 7 | |||
| 8 | our $VERSION = '0.102'; | ||
| 9 | |||
| 10 | has 'enclosure' => ( | ||
| 11 | is => 'rw', | ||
| 12 | isa => 'Net::PMP::Type::MediaEnclosures', | ||
| 13 | required => 1, | ||
| 14 | coerce => 1, | ||
| 15 | ); | ||
| 16 | |||
| 17 | sub get_profile_url {'https://api.pmp.io/profiles/media'} | ||
| 18 | |||
| 19 | sub get_type_from_uri { | ||
| 20 | my $self = shift; | ||
| 21 | my $uri = shift or confess "uri required"; | ||
| 22 | $uri =~ s/\?.*//; | ||
| 23 | $uri =~ s/.+\.(\w+)$/$1/; | ||
| 24 | my $type = try { | ||
| 25 | type_from_ext( lc $uri ); | ||
| 26 | } | ||
| 27 | catch { | ||
| 28 | confess $_; # re-throw with full stack trace | ||
| 29 | }; | ||
| 30 | return $type; | ||
| 31 | } | ||
| 32 | |||
| 33 | sub get_urn { | ||
| 34 | my $self = shift; | ||
| 35 | ( my $profile_name = $self->get_profile_url ) =~ s,^.+/,,; | ||
| 36 | return 'urn:collectiondoc:' . $profile_name; | ||
| 37 | } | ||
| 38 | |||
| 39 | __PACKAGE__->meta->make_immutable(); | ||
| 40 | |||
| 41 | 1; | ||
| 42 | |||
| 43 | __END__ |