File Coverage

blib/lib/App/sdview/Parser.pm
Criterion Covered Total %
statement 80 84 95.2
branch 2 2 100.0
condition 3 3 100.0
subroutine 28 30 93.3
pod n/a
total 113 119 94.9


line stmt bran cond sub pod time code
1             # You may distribute under the terms of either the GNU General Public License
2             # or the Artistic License (the same terms as Perl itself)
3             #
4             # (C) Paul Evans, 2022-2024 -- leonerd@leonerd.org.uk
5              
6 8     8   452686 use v5.26;
  8         32  
7 8     8   53 use warnings;
  8         16  
  8         537  
8 8     8   57 use utf8;
  8         18  
  8         63  
9              
10 8     8   1212 use Object::Pad 0.807;
  8         12456  
  8         401  
11 8     8   6194 use Object::Pad::FieldAttr::Checked 0.09;
  8         39566  
  8         43  
12              
13             package App::sdview::Parser 0.20;
14             role App::sdview::Parser;
15              
16 8     8   9415 use String::Tagged;
  8         149288  
  8         632  
17 8     8   75 use Data::Checks 0.05 qw( Num Str StrEq Isa Maybe );
  8         188  
  8         70  
18              
19             my $ListType;
20             BEGIN {
21 8     8   3958 $ListType = StrEq qw( bullet number text );
22             }
23              
24             # This package is empty but provides a bunch of helper classes
25              
26             class App::sdview::Para::Heading :strict(params) {
27 0     0   0 field $level :param :reader :Checked(Num);
  0         0  
28 26     26   1956 field $text :param :reader :Checked(Isa 'String::Tagged');
  26         161  
29              
30             method type { "head" . $level }
31              
32 15     15   29 method append_text ( $str, %tags ) { $text->append_tagged( $str, %tags ); }
  15         43  
  15         62  
  15         82  
  15         24  
  15         76  
33             }
34              
35             class App::sdview::Para::Plain :strict(params) {
36 151     151   10549 field $text :param :reader :Checked(Isa 'String::Tagged');
  151         884  
37 2     2   12 field $indent :param :reader :Checked(Num) = 0;
38              
39 2         13 method type { "plain" }
40              
41 56     56   106 method append_text ( $str, %tags ) { $text->append_tagged( $str, %tags ); }
  56         219  
  56         105  
  56         118  
  56         120  
  56         231  
42             }
43              
44             class App::sdview::Para::Verbatim :strict(params) {
45             field $language :param :reader :Checked(Maybe Str) = undef;
46 20     20   2458 field $text :param :reader :Checked(Isa 'String::Tagged');
  20     37   107  
  37         148  
  37         316  
47 0     0   0 field $indent :param :reader :Checked(Num) = 0;
48              
49 0         0 method type { "verbatim" }
50              
51 10     10   52 method append_text ( $str, %tags ) { $text->append_tagged( $str, %tags ); }
  10         35  
  10         23  
  10         38  
  10         17  
  10         49  
52             }
53              
54             class App::sdview::Para::List :strict(params) {
55 36     36   81 field $listtype :param :reader :Checked($ListType);
  36         146  
56 26     26   101 field $indent :param :reader :Checked(Num);
  26         126  
57 9     9   37 field $initial :param :reader :Checked(Num) = 1; # for number lists
58              
59 9     19   39 field @items :reader;
  19         75  
  19         89  
60              
61 63     63   254 method push_item ( $item ) { push @items, $item; }
  63         178  
  63         107  
  63         98  
  63         388  
62              
63             method type { "list-$listtype" }
64             }
65              
66             class App::sdview::Para::ListItem :strict(params) {
67 14     14   54 field $listtype :param :reader :Checked($ListType);
  14         96  
68             field $term :param :reader :Checked(Maybe Isa 'String::Tagged') = undef;
69 19     19   71 field $text :param :reader :Checked(Isa 'String::Tagged');
  19     69   100  
  69         1959  
  69         349  
70              
71             field $term_is_done = !!0;
72             method term_done { $term_is_done = !!1; }
73              
74             method type { "item" }
75              
76 43     43   79 method append_text ( $str, %tags ) {
  43         122  
  43         76  
  43         75  
  43         61  
77 43 100 100     348 ( defined $term && !$term_is_done ? $term : $text )
78             ->append_tagged( $str, %tags );
79             }
80             }
81              
82             class App::sdview::Para::Table :strict(params) {
83             method type { "table" }
84              
85 13     13   894 field @rows :reader;
  13         65  
86              
87             ADJUST :params ( :$rows ) {
88             @rows = $rows->@*;
89             }
90             }
91              
92             class App::sdview::Para::TableCell :strict(params) {
93             inherit App::sdview::Para::Plain;
94              
95 23     23   956 field $heading :param :reader = !!0;
96 23     41   126 field $align :param :reader :Checked(StrEq qw( left centre right ));
  41         122  
  41         251  
97              
98             method type { "table-cell" }
99             }
100              
101             0x55AA;