| 1 | package Yukki::Web::Plugin::Role::Formatter; | ||
| 2 | { | ||
| 3 | $Yukki::Web::Plugin::Role::Formatter::VERSION = '0.140290'; | ||
| 4 | } | ||
| 5 | use 5.12.1; | ||
| 6 | use Moose::Role; | ||
| 7 | |||
| 8 | # ABSTRACT: interface for HTML formatters | ||
| 9 | |||
| 10 | |||
| 11 | requires qw( html_formatters ); | ||
| 12 | |||
| 13 | |||
| 14 | sub has_format { | ||
| 15 | my ($self, $media_type) = @_; | ||
| 16 | return unless defined $media_type; | ||
| 17 | return defined $self->html_formatters->{$media_type}; | ||
| 18 | } | ||
| 19 | |||
| 20 | |||
| 21 | sub format { | ||
| 22 | my ($self, $params) = @_; | ||
| 23 | |||
| 24 | my $media_type = $params->{file}->media_type; | ||
| 25 | return unless $self->has_format($media_type); | ||
| 26 | |||
| 27 | my $format = $self->html_formatters->{$media_type}; | ||
| 28 | return $self->$format($params); | ||
| 29 | } | ||
| 30 | |||
| 31 | 1; | ||
| 32 | |||
| 33 | __END__ |