File Coverage

blib/lib/File/ArchivableFormats/Plugin.pm
Criterion Covered Total %
statement 9 12 75.0
branch 1 2 50.0
condition n/a
subroutine 3 4 75.0
pod 1 1 100.0
total 14 19 73.6


line stmt bran cond sub pod time code
1             package File::ArchivableFormats::Plugin;
2             our $VERSION = '1.8';
3 3     3   3511 use Moose::Role;
  3         15072  
  3         11  
4 3     3   17328 use namespace::autoclean;
  3         8  
  3         29  
5              
6             # ABSTRACT: Role which implements logic for all plugins
7              
8             requires '_build_preferred_formats';
9              
10             has preferred_formats => (
11             is => 'ro',
12             isa => 'HashRef',
13             traits => ['Hash'],
14             lazy => 1,
15             builder => '_build_preferred_formats',
16             handles => {
17             is_archivable => 'defined',
18             get_info => 'get',
19              
20             }
21             );
22              
23             has name => (
24             is => 'ro',
25             isa => 'Str',
26             required => 1,
27             );
28              
29             sub _not_allowed {
30 0     0   0 my $self = shift;
31 0         0 return { types => [], allowed_extensions => [] };
32             }
33              
34             sub allowed_extensions {
35 2     2 1 33 my ($self, $mimetype) = @_;
36              
37 2 50       136 if ($self->is_archivable($mimetype)) {
38 2         86 return $self->get_info($mimetype);
39             }
40              
41 0           return $self->_not_allowed;
42             }
43              
44             1;
45              
46             __END__
47              
48             =pod
49              
50             =encoding UTF-8
51              
52             =head1 NAME
53              
54             File::ArchivableFormats::Plugin - Role which implements logic for all plugins
55              
56             =head1 VERSION
57              
58             version 1.8
59              
60             =head1 ATTRIBUTES
61              
62             =head2 preferred_formats
63              
64             The list of preferred formats. Implements F <is_archivable> and F <get_info>
65              
66             =head2 name
67              
68             The (short) name of the plugin
69              
70             =head1 METHODS
71              
72             =head2 _build_preferred_formats
73              
74             Consumers of this role must implement this function to build the
75             C<preferred_formats> attribute.
76              
77             =head2 allowed_extensions
78              
79             Tells you if an extension is allowed, Returns an HashRef with data.
80              
81             {
82             types => [
83             # Tells you something about the filetype
84             ],
85             allowed_extensions => [
86             # Tells you which extensions are allowed for the mimetype in
87             # the preferred formats list
88             ],
89             }
90              
91             =head1 AUTHOR
92              
93             Wesley Schwengle <wesley@mintlab.nl>
94              
95             =head1 COPYRIGHT AND LICENSE
96              
97             This software is Copyright (c) 2017 by Mintlab BV.
98              
99             This is free software, licensed under:
100              
101             The European Union Public License (EUPL) v1.1
102              
103             =cut