File Coverage

blib/lib/Gherkin/Dialect.pm
Criterion Covered Total %
statement 39 46 84.7
branch 4 10 40.0
condition 1 2 50.0
subroutine 18 19 94.7
pod 13 14 92.8
total 75 91 82.4


line stmt bran cond sub pod time code
1             package Gherkin::Dialect;
2             $Gherkin::Dialect::VERSION = '39.0.0';
3 1     1   9 use strict;
  1         3  
  1         71  
4 1     1   5 use warnings;
  1         4  
  1         71  
5              
6 1     1   7 use Cucumber::Messages;
  1         2  
  1         24  
7 1     1   5 use Gherkin::Exceptions;
  1         2  
  1         56  
8              
9 1         13 use Class::XSAccessor accessors =>
10 1     1   6 [ qw/_current_dialect dialect dictionary_location dictionary /, ];
  1         33  
11              
12             sub new {
13 3     3 1 9 my ( $class, $options ) = @_;
14 3   50     15 $options->{'dialect'} ||= 'en';
15              
16 3 50       11 unless ( $options->{'dictionary'} ) {
17              
18             # Load from a file if one was given
19 3 50       12 if ( my $filename = $options->{'dictionary_location'} ) {
20 0         0 require Cpanel::JSON::XS;
21 0 0       0 open( my $fh, '<', $filename ) || die "Can't open [$filename]";
22 0         0 my $input = join '', (<$fh>);
23 0         0 close $fh;
24 0         0 $options->{'dictionary'} = Cpanel::JSON::XS::decode_json($input);
25             } else {
26             ## no critic (ProhibitPackageVars)
27 3         902 require Gherkin::Generated::Languages;
28 3         15 $options->{'dictionary'} = $Gherkin::Generated::Languages::data;
29             ## use critic
30             }
31             }
32              
33 3         13 bless $options, $class;
34             $options->change_dialect( $options->{'dialect'} )
35 3 50       31 if $options->{'dialect'};
36              
37 3         17 return $options;
38             }
39              
40             sub change_dialect {
41 9     9 1 64 my ( $self, $name, $location ) = @_;
42             Gherkin::Exceptions::NoSuchLanguage->throw( $name, $location )
43 9 50       66 unless $self->dictionary->{$name};
44 9         50 $self->{'dialect'} = $name;
45 9         49 $self->{'_current_dialect'} = $self->dictionary->{$name};
46             }
47              
48 3     3 1 47 sub Feature { $_[0]->_current_dialect->{'feature'}; }
49 9     9 1 32 sub Rule { $_[0]->_current_dialect->{'rule'}; }
50 15     15 1 64 sub Scenario { $_[0]->_current_dialect->{'scenario'}; }
51 3     3 1 20 sub Background { $_[0]->_current_dialect->{'background'}; }
52 6     6 1 31 sub Examples { $_[0]->_current_dialect->{'examples'}; }
53 12     12 1 60 sub Given { $_[0]->_current_dialect->{'given'}; }
54 12     12 1 43 sub When { $_[0]->_current_dialect->{'when'}; }
55 12     12 1 41 sub Then { $_[0]->_current_dialect->{'then'}; }
56 12     12 1 37 sub And { $_[0]->_current_dialect->{'and'}; }
57 12     12 1 70 sub But { $_[0]->_current_dialect->{'but'}; }
58              
59              
60             sub stepKeywordTypes {
61 0     0 0 0 return @{ $_[0]->{'_step_keywords'}->{$_[1]} };
  0         0  
62             }
63              
64             sub ScenarioOutline {
65 9     9 1 29 $_[0]->_current_dialect->{'scenarioOutline'};
66             }
67              
68             1;
69              
70              
71             __END__