File Coverage

blib/lib/Colouring/In/XS.pm
Criterion Covered Total %
statement 24 30 80.0
branch 6 10 60.0
condition 2 4 50.0
subroutine 6 7 85.7
pod 1 2 50.0
total 39 53 73.5


line stmt bran cond sub pod time code
1             package Colouring::In::XS;
2              
3 19     19   1968692 use 5.006;
  19         71  
4 19     19   104 use strict;
  19         118  
  19         747  
5 19     19   125 use warnings;
  19         66  
  19         3025  
6              
7             our $VERSION = '0.10';
8              
9             require XSLoader;
10             XSLoader::load('Colouring::In::XS', $VERSION);
11              
12             sub import {
13 19     19   170 my ($pkg, @exports) = @_;
14 19         48 my $caller = caller;
15 19 100       97 set_messages(pop @exports) if (ref $exports[-1] eq 'HASH');
16 19 100       12240 if (scalar @exports) {
17 19     19   135 no strict 'refs';
  19         50  
  19         6480  
18 11         25 *{"${caller}::${_}"} = \&{"${_[0]}::${_}"} foreach @exports;
  11         16454  
  11         101  
19             }
20             }
21              
22             sub include_dir {
23 0     0 0 0 my $dir = $INC{'Colouring/In/XS.pm'};
24             # Installed: .../Colouring/In/XS.pm → .../Colouring/In/XS/include
25 0         0 (my $installed = $dir) =~ s{XS\.pm$}{XS/include};
26 0 0       0 return $installed if -d $installed;
27             # Development: lib/Colouring/In/XS.pm → include
28 0         0 (my $dev = $dir) =~ s{lib/Colouring/In/XS\.pm$}{include};
29 0 0       0 return $dev if -d $dev;
30 0         0 return $installed;
31             }
32              
33             sub validate {
34 4     4 1 133449 my ($self, $colour) = @_;
35 4         6 my $new = eval { $self->new($colour) };
  4         34  
36 4 100       9 if ($@) {
37             return {
38 3   50     22 valid => \0,
39             message => get_message('VALIDATE_ERROR') || 'The string passed to Colouring::In::XS::validate is not a valid color.',
40             color => $colour
41             };
42             }
43             return {
44 1   50     11 valid => \1,
45             message => get_message('VALIDATE') || 'The string passed to Colouring::In::XS::validate is a valid color',
46             color => $colour,
47             colour => $new
48             };
49             }
50              
51             1;
52              
53             __END__