File Coverage

blib/lib/Marpa/R2/HTML/Config.pm
Criterion Covered Total %
statement 45 46 97.8
branch 4 6 66.6
condition n/a
subroutine 10 10 100.0
pod 0 5 0.0
total 59 67 88.0


line stmt bran cond sub pod time code
1             # Copyright 2022 Jeffrey Kegler
2             # This file is part of Marpa::R2. Marpa::R2 is free software: you can
3             # redistribute it and/or modify it under the terms of the GNU Lesser
4             # General Public License as published by the Free Software Foundation,
5             # either version 3 of the License, or (at your option) any later version.
6             #
7             # Marpa::R2 is distributed in the hope that it will be useful,
8             # but WITHOUT ANY WARRANTY; without even the implied warranty of
9             # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10             # Lesser General Public License for more details.
11             #
12             # You should have received a copy of the GNU Lesser
13             # General Public License along with Marpa::R2. If not, see
14             # http://www.gnu.org/licenses/.
15              
16             package Marpa::R2::HTML::Config;
17              
18 8     8   141 use 5.010001;
  8         25  
19 8     8   40 use strict;
  8         13  
  8         172  
20 8     8   36 use warnings;
  8         28  
  8         212  
21              
22 8     8   41 use vars qw($VERSION $STRING_VERSION);
  8         15  
  8         703  
23             $VERSION = '13.001_000';
24             $STRING_VERSION = $VERSION;
25             ## no critic(BuiltinFunctions::ProhibitStringyEval)
26             $VERSION = eval $VERSION;
27             ## use critic
28              
29 8     8   53 use English qw( -no_match_vars );
  8         23  
  8         60  
30              
31             # Generate the default configuration
32             sub new {
33 93     93 0 215 my ($class) = @_;
34 93         15863 require Marpa::R2::HTML::Config::Default;
35 93         441 my $self = {
36             rules => $Marpa::R2::HTML::Internal::Config::Default::CORE_RULES,
37             runtime_tag =>
38             $Marpa::R2::HTML::Internal::Config::Default::RUNTIME_TAG,
39             ruby_slippers_rank_by_name =>
40             $Marpa::R2::HTML::Internal::Config::Default::RUBY_SLIPPERS_RANK_BY_NAME,
41             is_empty_element =>
42             $Marpa::R2::HTML::Internal::Config::Default::IS_EMPTY_ELEMENT,
43             primary_group_by_tag =>
44             $Marpa::R2::HTML::Internal::Config::Default::PRIMARY_GROUP_BY_TAG
45             };
46 93         345 return bless $self, $class;
47             } ## end sub new
48              
49             sub new_from_compile {
50 1     1 0 3 my ( $class, $source_ref ) = @_;
51 1         515 require Marpa::R2::HTML::Config::Compile;
52 1         4 return bless Marpa::R2::HTML::Config::Compile::compile($source_ref), $class;
53             } ## end sub new_from_compile
54              
55             sub contents {
56 96     96 0 188 my ($self) = @_;
57 96         379 return @{$self}{
58 96         163 qw( rules runtime_tag
59             ruby_slippers_rank_by_name is_empty_element
60             primary_group_by_tag
61             )
62             };
63             } ## end sub contents
64              
65             my $legal_preamble = <<'END_OF_TEXT';
66             # Copyright 2022 Jeffrey Kegler
67             # This file is part of Marpa::R2. Marpa::R2 is free software: you can
68             # redistribute it and/or modify it under the terms of the GNU Lesser
69             # General Public License as published by the Free Software Foundation,
70             # either version 3 of the License, or (at your option) any later version.
71             #
72             # Marpa::R2 is distributed in the hope that it will be useful,
73             # but WITHOUT ANY WARRANTY; without even the implied warranty of
74             # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
75             # Lesser General Public License for more details.
76             #
77             # You should have received a copy of the GNU Lesser
78             # General Public License along with Marpa::R2. If not, see
79             # http://www.gnu.org/licenses/.
80              
81             END_OF_TEXT
82              
83             sub sort_bnf {
84 910     910 0 1105 my $cmp = $a->{lhs} cmp $b->{lhs};
85 910 100       1215 return $cmp if $cmp;
86 127         175 my $a_rhs_length = scalar @{ $a->{rhs} };
  127         174  
87 127         134 my $b_rhs_length = scalar @{ $b->{rhs} };
  127         139  
88 127         136 $cmp = $a_rhs_length <=> $b_rhs_length;
89 127 50       170 return $cmp if $cmp;
90 127         177 for my $ix ( 0 .. $a_rhs_length ) {
91 127         163 $cmp = $a->{rhs}->[$ix] cmp $b->{rhs}->[$ix];
92 127 50       221 return $cmp if $cmp;
93             }
94 0         0 return 0;
95             } ## end sub sort_bnf
96              
97             sub as_string {
98 2     2 0 6 my ($self) = @_;
99              
100 2         21 require Data::Dumper;
101 2         8 require Marpa::R2::HTML::Config::Default;
102              
103 2         6 local $Data::Dumper::Purity = 1;
104 2         6 local $Data::Dumper::Sortkeys = 1;
105 2         7 my @contents = $self->contents();
106 2         5 my @rules = sort sort_bnf @{$contents[0]};
  2         17  
107 2         7 $contents[0] = \@rules;
108              
109             # Start with the legal language
110             return \(
111 2         140 $legal_preamble
112             . '# This file was generated automatically by '
113             . __PACKAGE__ . "\n"
114             . '# The date of generation was '
115             . ( scalar localtime() ) . "\n" . "\n"
116             . "package Marpa::R2::HTML::Internal::Config::Default;\n" . "\n"
117             . Data::Dumper->Dump(
118             \@contents,
119             [ qw( CORE_RULES RUNTIME_TAG
120             RUBY_SLIPPERS_RANK_BY_NAME IS_EMPTY_ELEMENT
121             PRIMARY_GROUP_BY_TAG
122             )
123             ]
124             )
125             );
126              
127             } ## end sub as_string
128              
129             1;
130              
131             # vim: set expandtab shiftwidth=4: