File Coverage

blib/lib/Pistachio/Supported.pm
Criterion Covered Total %
statement 33 33 100.0
branch 2 4 50.0
condition n/a
subroutine 10 10 100.0
pod 0 2 0.0
total 45 49 91.8


line stmt bran cond sub pod time code
1             package Pistachio::Supported;
2             # ABSTRACT: provides supported_languages() and supported_styles()
3              
4 1     1   842 use strict;
  1         3  
  1         45  
5 1     1   6 use warnings;
  1         2  
  1         55  
6             our $VERSION = '0.10'; # VERSION
7              
8 1     1   638 use Pistachio::Tokenizer;
  1         3  
  1         31  
9 1     1   703 use Pistachio::Language;
  1         3  
  1         25  
10 1     1   503 use Pistachio::Html;
  1         2  
  1         34  
11              
12 1     1   6 use Exporter 'import';
  1         1  
  1         300  
13             our @EXPORT_OK = qw(supported_languages supported_styles);
14              
15             my @languages = qw(
16             Perl5
17             );
18              
19             my @styles = qw(
20             Github
21             );
22              
23             # @return array list of supported languages
24             sub supported_languages {
25 1     1 0 844 _eval(@$_) for &_pair_up;
26 1         7 @languages;
27             }
28              
29             # @return array list of supported styles
30             sub supported_styles {
31 1     1 0 736 _eval(@$_) for &_pair_up;
32 1         6 @styles;
33             }
34              
35             # @param string $l a language, e.g., 'Perl5'
36             # @param string $s a style, e.g., 'Github'
37             sub _eval($$) {
38 2     2   4 my ($l, $s) = @_;
39              
40 2         2 eval { Pistachio::Tokenizer->new(Pistachio::Language->new($l)) };
  2         13  
41 2 50       25 die "Language `$l` should be supported -- $@" if $@;
42              
43 2         3 eval { Pistachio::Html->new($l, $s) };
  2         9  
44 2 50       35 die "Style `$s` should be supported -- $@" if $@;
45             }
46              
47             # @return array pairs of [language, style]
48             sub _pair_up() {
49 2     2   4 my @pairs;
50 2         5 for my $l (@languages) { push @pairs, [$l, $_] for @styles }
  2         13  
51 2         9 @pairs;
52             }
53              
54             1;
55              
56             __END__