File Coverage

blib/lib/Convert/Color/ScaleModels.pm
Criterion Covered Total %
statement 56 61 91.8
branch 30 34 88.2
condition 17 21 80.9
subroutine 8 8 100.0
pod 3 3 100.0
total 114 127 89.7


line stmt bran cond sub pod time code
1             package Convert::Color::ScaleModels;
2              
3 3     3   26269 use 5.006;
  3         11  
  3         129  
4 3     3   20 use strict;
  3         5  
  3         138  
5 3     3   22 use warnings;
  3         9  
  3         105  
6 3     3   16 use Carp;
  3         5  
  3         4858  
7              
8             my $names_colors;
9              
10             =head1 NAME
11              
12             Convert::Color::ScaleModels - converts between color numbers from scale model paint manufacturers (Humbrol, Revell, Tamiya)
13              
14             =head1 VERSION
15              
16             Version 0.03
17              
18             =cut
19              
20             our $VERSION = '0.03';
21              
22              
23             =head1 SYNOPSIS
24              
25             This module converts between color numbers from scale model paint manufacturers (Humbrol, Revell, Tamiya).
26              
27             use Convert::Color::ScaleModels;
28              
29             my $color = Convert::Color::ScaleModels->new();
30              
31             my $revell_flesh_num = $color->convert('61', 'humbrol', 'revell');
32             print "manufacturer = $color->{man}\n"; # 'revell'
33             print "color name = $color->{name}\n"; # 'flesh matt'
34             print "color number = $color->{num}\n"; # 35
35             print "color number (return value from method) = $revell_flesh_num\n"; # also 35
36              
37             The color number values are taken from Humbrol's own conversion tables (L).
38              
39             =head1 SUBROUTINES/METHODS
40              
41             =head2 new
42              
43             Creates new color object. Each object carries a color name (C), color number (C) and manufacturer name (C), undefined at object creation.
44            
45             my $color = Convert::Color::ScaleModels->new();
46              
47             =cut
48              
49             sub new {
50 2     2 1 1613 my $class = shift;
51 2         5 my $self = {};
52              
53 2         5 $self->{name} = undef;
54 2         3 $self->{num} = undef;
55 2         4 $self->{man} = undef;
56              
57 2         6 bless( $self, $class );
58 2         4 return $self;
59             }
60              
61             =head2 convert
62              
63             Converts between color numbers from scale model paint manufacturers (Humbrol, Revell, Tamiya). The object properties (C, C and C) are set after conversion.
64             For instance, to convert color number 61 ('flesh matt') from Humbrol to the corresponding value from Revell (if available), use
65              
66             my $revell_flesh_num = $color->convert(61, 'humbrol', 'revell'); # $revell_flesh_num = 35
67              
68             =cut
69              
70             sub convert {
71 6     6 1 671 my $self = shift;
72 6         50 my ($colornum, $man1, $man2) = @_;
73            
74 6 50 33     13 return undef unless (_valid_man($man1)
75             && _valid_man($man2));
76              
77 6 50       12 if ($man1 eq $man2) {
78             # no conversion needed
79 0         0 $self->{man} = $man1;
80 0         0 $self->{num} = $colornum;
81             } else {
82             # lookup color table
83 6         7 my ($newcolor, $cname);
84 6         100 foreach my $name ( keys %$names_colors ) {
85 906 100       1978 if ($man1 =~ /humbrol/i) {
    100          
86 302 100 66     1564 next unless defined($names_colors->{$name}->[0])
87             and $colornum eq $names_colors->{$name}->[0];
88 2 100       9 if ($man2 =~ /revell/i) {
89 1         4 $newcolor = $names_colors->{$name}->[1];
90             } else { # $man2 matches 'tamiya'
91 1         4 $newcolor = $names_colors->{$name}->[2];
92             }
93 2         4 $cname = $name;
94             } elsif ($man1 =~ /revell/i) {
95 302 100 100     1003 next unless defined($names_colors->{$name}->[1])
96             and $colornum eq $names_colors->{$name}->[1];
97 2 100       7 if ($man2 =~ /humbrol/i) {
98 1         4 $newcolor = $names_colors->{$name}->[0];
99             } else { # $man2 matches 'tamiya'
100 1         3 $newcolor = $names_colors->{$name}->[2];
101             }
102 2         4 $cname = $name;
103             } else { # $man1 matches 'tamiya'
104 302 100 100     904 next unless defined($names_colors->{$name}->[2])
105             and $colornum eq $names_colors->{$name}->[2];
106 2 100       8 if ($man2 =~ /humbrol/i) {
107 1         3 $newcolor = $names_colors->{$name}->[0];
108             } else { # $man2 matches 'revell'
109 1         3 $newcolor = $names_colors->{$name}->[1];
110             }
111 2         4 $cname = $name;
112             }
113             }
114              
115 6         52 $self->{man} = $man2;
116 6         9 $self->{num} = $newcolor;
117 6         10 $self->{name} = $cname;
118             }
119 6         35 return $self->{num};
120             }
121              
122             =head2 name
123              
124             Returns color name, given color number and manufacturer. Otherwise, returns C.
125              
126             print $color->name('65', 'humbrol'); # 'aircraft blue matt'
127              
128             =cut
129              
130             sub name {
131 3     3 1 445 my $self = shift;
132 3         5 my ($cnum, $man) = @_;
133              
134 3 50       5 return undef unless _valid_man($man);
135            
136 3         61 foreach my $name ( keys %$names_colors ) {
137 352 100       823 if ($man =~ /humbrol/i) {
    100          
138 136 100 66     687 return $name if defined($names_colors->{$name}->[0])
139             and $cnum eq $names_colors->{$name}->[0];
140             } elsif ($man =~ /revell/i) {
141 146 100 100     438 return $name if defined($names_colors->{$name}->[1])
142             and $cnum eq $names_colors->{$name}->[1];
143             } else { # $man matches 'tamiya'
144 70 100 100     231 return $name if defined($names_colors->{$name}->[2])
145             and $cnum eq $names_colors->{$name}->[2];
146             }
147             }
148 0         0 return undef;
149             }
150              
151             sub _valid_man {
152 15     15   19 my $man = shift;
153 15 50       93 if ($man =~ /(humbrol|revell|tamiya)/i) {
154 15         61 return 1;
155             } else {
156             # manufacturer unknown
157 0           croak "Manufacturer unknown: $man";
158 0           return undef;
159             }
160             }
161              
162             =head1 AUTHOR
163              
164             Ari Constancio, C<< >>
165              
166             =head1 BUGS
167              
168             Please report any bugs or feature requests to C, or through
169             the web interface at L. I will be notified, and then you'll
170             automatically be notified of progress on your bug as I make changes.
171              
172             =head1 SUPPORT
173              
174             You can find documentation for this module with the perldoc command.
175              
176             perldoc Convert::Color::ScaleModels
177              
178              
179             You can also look for information at:
180              
181             =over 4
182              
183             =item * RT: CPAN's request tracker (report bugs here)
184              
185             L
186              
187             =item * AnnoCPAN: Annotated CPAN documentation
188              
189             L
190              
191             =item * CPAN Ratings
192              
193             L
194              
195             =item * Search CPAN
196              
197             L
198              
199             =back
200              
201             =head1 LICENSE AND COPYRIGHT
202              
203             Copyright 2012 Ari Constancio.
204              
205             This program is free software; you can redistribute it and/or modify it
206             under the terms of either: the GNU General Public License as published
207             by the Free Software Foundation; or the Artistic License.
208              
209             See http://dev.perl.org/licenses/ for more information.
210              
211              
212             =cut
213              
214             $names_colors = {
215             "grey primer" => [1, undef, undef ],
216             "emerald green gloss" => [2, undef, undef ],
217             "brunswick green gloss" => [3, undef, "x5" ],
218             "dark admiral grey gloss" => [5, undef, undef ],
219             "light buff gloss" => [7, undef, undef ],
220             "tan gloss" => [9, undef, undef ],
221             "service brown gloss" => [10, 81, "x9" ],
222             "silver metallic" => [11, 90, "x11" ],
223             "copper metallic" => [12, undef, "xf6" ],
224             "french blue gloss" => [14, 52, "x4" ],
225             "midnight blue gloss" => [15, undef, "x3" ],
226             "gold metallic" => [16, 94, "x12" ],
227             "orange gloss" => [18, 30, "x6" ],
228             "bright red gloss" => [19, 31, "x7" ],
229             "crimson gloss" => [20, undef, undef ],
230             "black gloss" => [21, 7, "x1" ],
231             "white gloss" => [22, 4, "x2" ],
232             "duck egg blue matt" => [23, undef, undef ],
233             "trainer yellow matt" => [24, 15, undef ],
234             "blue matt" => [25, 56, "xf8" ],
235             "khaki matt" => [26, 86, "xf49" ],
236             "sea grey matt" => [27, undef, "xf54" ],
237             "camouflage grey matt" => [28, undef, "xf55" ],
238             "dark earth matt" => [29, 87, "xf52" ],
239             "dark green matt" => [30, undef, "xf61" ],
240             "slate grey matt" => [31, undef, undef ],
241             "dark grey matt" => [32, undef, undef ],
242             "black matt" => [33, 8, "xf1" ],
243             "white matt" => [34, 5, "xf2" ],
244             "varnish gloss" => [35, 1, undef ],
245             "lime gloss" => [38, undef, "x15" ],
246             "pale grey gloss" => [40, undef, undef ],
247             "ivory gloss" => [41, 10, undef ],
248             "sea blue gloss" => [47, undef, undef ],
249             "mediterranian blue gloss" => [48, 51, "x14" ],
250             "varnish matt" => [49, 2, undef ],
251             "green mist metallic" => [50, 97, undef ],
252             "sunset red metallic" => [51, 96, undef ],
253             "baltic blue metallic" => [52, 96, "x13" ],
254             "gunmetal metallic" => [53, undef, "x10" ],
255             "brass metallic" => [54, 93, undef ],
256             "bronze metallic" => [55, 95, undef ],
257             "aluminium metallic" => [56, 99, "xf56" ],
258             "scarlet matt" => [60, 36, "xf7" ],
259             "flesh matt" => [61, 35, "xf15" ],
260             "leather matt" => [62, 85, undef ],
261             "sand matt" => [63, undef, "xf59" ],
262             "light grey matt" => [64, 75, "xf12" ],
263             "aircraft blue matt" => [65, 55, "xf23" ],
264             "olive drab matt" => [66, 53, "xf62" ],
265             "tank grey matt" => [67, 78, undef ],
266             "purple gloss" => [68, undef, "x16" ],
267             "yellow gloss" => [69, 12, "x8" ],
268             "brick red matt" => [70, 37, undef ],
269             "oak satin" => [71, undef, undef ],
270             "khaki drill matt" => [72, undef, undef ],
271             "wine matt" => [73, undef, "xf9" ],
272             "linen matt" => [74, undef, undef ],
273             "bronze green matt" => [75, undef, "xf11" ],
274             "uniform green matt" => [76, undef, undef ],
275             "navy blue matt" => [77, undef, undef ],
276             "cockpit green matt" => [78, undef, undef ],
277             "blue grey matt" => [79, 77, undef ],
278             "grass green matt" => [80, undef, undef ],
279             "pale yellow matt" => [81, undef, "xf4" ],
280             "orange lining matt" => [82, undef, undef ],
281             "ochre matt" => [83, undef, "xf57" ],
282             "mid stone matt" => [84, undef, "xf60" ],
283             "coal black satin" => [85, 9, "x18" ],
284             "light olive matt" => [86, 45, undef ],
285             "steel grey matt" => [87, undef, "xf25" ],
286             "deck green matt" => [88, 48, undef ],
287             "mid blue matt" => [89, undef, undef ],
288             "beige green matt" => [90, undef, "xf21" ],
289             "black green matt" => [91, 67, "xf27" ],
290             "iron grey matt" => [92, 79, "xf22" ],
291             "desert yellow matt" => [93, undef, undef ],
292             "brown yellow matt" => [94, 16, undef ],
293             "raf blue matt" => [96, undef, "xf18" ],
294             "chocolate matt" => [98, undef, "xf10" ],
295             "lemon yellow matt" => [99, undef, "xf3" ],
296             "red brown matt" => [100, undef, undef ],
297             "mid green matt" => [101, 364, "xf5" ],
298             "army green matt" => [102, undef, undef ],
299             "cream matt" => [103, undef, undef ],
300             "oxford blue matt" => [104, undef, "xf17" ],
301             "marine green matt" => [105, 361, undef ],
302             "ocean grey matt" => [106, 47, undef ],
303             "ww1 blue matt" => [109, undef, undef ],
304             "natural wood matt" => [110, undef, undef ],
305             "tarmac" => [112, 71, "xf24" ],
306             "rust matt" => [113, undef, undef ],
307             "us dark green matt" => [116, undef, "xf13" ],
308             "us light green matt" => [117, undef, undef ],
309             "us tan matt" => [118, 382, undef ],
310             "light earth matt" => [119, undef, undef ],
311             "light green matt" => [120, undef, undef ],
312             "pale stone matt" => [121, undef, undef ],
313             "extra dark sea grey satin" => [123, undef, "xf58" ],
314             "us dark grey satin" => [125, undef, undef ],
315             "us medium grey satin" => [126, undef, "xf20" ],
316             "us ghost grey satin" => [127, undef, undef ],
317             "us compass grey satin" => [128, 374, undef ],
318             "us gull grey satin" => [129, undef, undef ],
319             "white satin" => [130, 301, undef ],
320             "mid green satin" => [131, undef, undef ],
321             "red satin" => [132, undef, undef ],
322             "brown satin" => [133, undef, undef ],
323             "varnish satin" => [135, undef, undef ],
324             "gull grey matt" => [140, undef, undef ],
325             "intermediate blue matt" => [144, undef, undef ],
326             "medium grey matt" => [145, undef, undef ],
327             "light grey matt" => [147, undef, "xf14" ],
328             "radome tan matt" => [148, undef, undef ],
329             "foliage green matt" => [149, undef, "xf26" ],
330             "forest green matt" => [150, undef, undef ],
331             "insignia red matt" => [153, undef, undef ],
332             "insignia yellow matt" => [154, undef, undef ],
333             "olive drab matt" => [155, undef, undef ],
334             "dark camoflage grey satin" => [156, undef, "xf53" ],
335             "azure blue matt" => [157, undef, undef ],
336             "khaki drab matt" => [159, undef, undef ],
337             "german cam red brown matt" => [160, undef, undef ],
338             "dark green satin" => [163, undef, undef ],
339             "dark sea grey satin" => [164, undef, undef ],
340             "medium sea grey satin" => [165, undef, undef ],
341             "light aircraft grey satin" => [166, undef, undef ],
342             "raf barley grey satin" => [167, undef, undef ],
343             "hemp satin" => [168, undef, undef ],
344             "antique bronze metallic" => [171, undef, undef ],
345             "signal red satin" => [174, undef, undef ],
346             "brown matt" => [186, undef, undef ],
347             "dark stone matt" => [187, undef, undef ],
348             "chrome silver metallic" => [191, undef, undef ],
349             "chrome green satin" => [195, 363, undef ],
350             "light grey satin" => [196, 371, undef ],
351             "pink gloss" => [200, undef, "x17" ],
352             "black metallic" => [201, undef, undef ],
353             "signal green gloss" => [208, undef, undef ],
354             "ferrari red gloss" => [220, undef, undef ],
355             "moonlight blue metallic" => [222, undef, undef ],
356             "dark slate grey matt" => [224, undef, undef ],
357             "middle stone matt" => [225, undef, undef ],
358             "interior green matt" => [226, undef, undef ],
359             "pru blue matt" => [230, undef, undef ],
360             "desert sand matt" => [250, undef, undef ],
361             "red clear" => [1321, undef, undef ],
362             "orange clear" => [1322, undef, undef ],
363             "green clear" => [1325, undef, undef ],
364             "aluminium metalcote" => [27001, undef, undef ],
365             "polish. aluminium metalcote" => [27002, undef, undef ],
366             "polished steel metalcote" => [27003, undef, undef ],
367             "gunmetal metalcote" => [27004, undef, undef ],
368             };
369              
370             1; # End of Convert::Color::ScaleModels