File Coverage

blib/lib/Game/Asset/Type.pm
Criterion Covered Total %
statement 14 14 100.0
branch 1 2 50.0
condition n/a
subroutine 4 4 100.0
pod 1 1 100.0
total 20 21 95.2


line stmt bran cond sub pod time code
1             # Copyright (c) 2016 Timm Murray
2             # All rights reserved.
3             #
4             # Redistribution and use in source and binary forms, with or without
5             # modification, are permitted provided that the following conditions are met:
6             #
7             # * Redistributions of source code must retain the above copyright notice,
8             # this list of conditions and the following disclaimer.
9             # * Redistributions in binary form must reproduce the above copyright
10             # notice, this list of conditions and the following disclaimer in the
11             # documentation and/or other materials provided with the distribution.
12             #
13             # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
14             # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15             # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16             # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
17             # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18             # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19             # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20             # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21             # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22             # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
23             # POSSIBILITY OF SUCH DAMAGE.
24             package Game::Asset::Type;
25             $Game::Asset::Type::VERSION = '0.5';
26 7     7   535 use strict;
  7         17  
  7         171  
27 7     7   30 use warnings;
  7         13  
  7         144  
28 7     7   2698 use Moose::Role;
  7         31704  
  7         26  
29              
30              
31             requires 'type';
32             requires '_process_content';
33              
34             has 'name' => (
35             is => 'ro',
36             isa => 'Str',
37             required => 1,
38             );
39             has 'full_name' => (
40             is => 'ro',
41             isa => 'Str',
42             required => 1,
43             );
44             has 'has_been_processed' => (
45             traits => ['Bool'],
46             is => 'ro',
47             isa => 'Bool',
48             handles => {
49             '_set_has_been_processed' => 'set',
50             },
51             );
52             has '_orig_content' => (
53             is => 'rw',
54             isa => 'Str',
55             );
56              
57              
58             sub process_content
59             {
60 8     8 1 30 my ($self, $content, @args) = @_;
61 8 50       244 return if $self->has_been_processed;
62 8         54 $self->_process_content( $content, @args );
63 8         264 $self->_set_has_been_processed;
64 8         29 return;
65             }
66              
67              
68             1;
69             __END__
70              
71              
72             =head1 NAME
73              
74             Game::Asset::Type - Role for asset types
75              
76             =head1 DESCRIPTION
77              
78             Each file in the asset archive is represented by a class that does this role.
79             Types are determined by L<Game::Asset> using the file extension.
80              
81             =head1 PROVIDES
82              
83             =head2 process_content
84              
85             This is called with the full data. If it's the first time the data was passed,
86             then it calls C<_process_content()> and sets C<has_been_processed()> to true.
87              
88             Any additional arguments passed to this will be passed to
89             C<_process_content()>.
90              
91             =head2 name
92              
93             The short name (without extension) of the asset.
94              
95             =head2 full_name
96              
97             The full name (with extension) of the asset.
98              
99             =head2 has_been_processed
100              
101             Boolean. If true, then the asset data has already been passed once to
102             C<process_content()>.
103              
104             =head2 _orig_content
105              
106             The C<_process_content()> method should set this to the original, untouched
107             data passed in.
108              
109             =head1 REQUIRES
110              
111             =head2 type
112              
113             Returns the name of the type.
114              
115             =head2 _process_content
116              
117             Passed the untouched data so it can be processed.
118              
119             =cut