File Coverage

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


line stmt bran cond sub pod time code
1             package Colouring::In::XS;
2              
3 18     18   1813352 use 5.006;
  18         69  
4 18     18   89 use strict;
  18         81  
  18         639  
5 18     18   87 use warnings;
  18         65  
  18         2963  
6              
7             our $VERSION = '0.09';
8              
9             require XSLoader;
10             XSLoader::load('Colouring::In::XS', $VERSION);
11              
12             sub import {
13 18     18   187 my ($pkg, @exports) = @_;
14 18         42 my $caller = caller;
15 18 100       108 set_messages(pop @exports) if (ref $exports[-1] eq 'HASH');
16 18 100       10647 if (scalar @exports) {
17 18     18   126 no strict 'refs';
  18         45  
  18         6462  
18 11         26 *{"${caller}::${_}"} = \&{"${_[0]}::${_}"} foreach @exports;
  11         16729  
  11         52  
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 125955 my ($self, $colour) = @_;
35 4         6 my $new = eval { $self->new($colour) };
  4         34  
36 4 100       11 if ($@) {
37             return {
38 3   100     0 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__