File Coverage

blib/lib/Test/BDD/Cucumber/Model/Line.pm
Criterion Covered Total %
statement 28 31 90.3
branch 1 2 50.0
condition 2 2 100.0
subroutine 11 12 91.6
pod 7 7 100.0
total 49 54 90.7


line stmt bran cond sub pod time code
1 17     17   220 use v5.14;
  17         62  
2 17     17   110 use warnings;
  17         53  
  17         771  
3              
4             package Test::BDD::Cucumber::Model::Line 0.85;
5              
6 17     17   125 use Moo;
  17         38  
  17         145  
7 17     17   5710 use Types::Standard qw( Int InstanceOf Str );
  17         86  
  17         126  
8              
9             =head1 NAME
10              
11             Test::BDD::Cucumber::Model::Line - Model to represent a line in a feature file
12              
13             =head1 VERSION
14              
15             version 0.85
16              
17             =head1 DESCRIPTION
18              
19             Model to represent a line in a feature file
20              
21             =head1 ATTRIBUTES
22              
23             =head2 number
24              
25             The line number this line represents
26              
27             =cut
28              
29             has 'number' => ( is => 'rw', isa => Int );
30              
31             =head2 document
32              
33             The L object this line belongs to.
34              
35             =cut
36              
37             has 'document' => ( is => 'rw', isa => InstanceOf['Test::BDD::Cucumber::Model::Document'] );
38              
39             =head2 raw_content
40              
41             The content of the line, unmodified
42              
43             =cut
44              
45             has 'raw_content' => ( is => 'rw', isa => Str );
46              
47             =head1 METHODS
48              
49             =head2 indent
50              
51             Returns the number of preceding spaces before content on a line
52              
53             =cut
54              
55             sub indent {
56 27     27 1 52 my $self = shift;
57 27         483 my ($indent) = $self->raw_content =~ m/^( +)/g;
58 27   100     371 return length( $indent || '' );
59             }
60              
61             =head2 content
62              
63             Returns the line's content, with the indentation stripped
64              
65             =cut
66              
67 5490     5490 1 88755 sub content { return _strip( $_[0]->raw_content ) }
68              
69             =head2 content_remove_indentation
70              
71             Accepts an int of number of spaces, and returns the content with exactly that
72             many preceding spaces removed.
73              
74             =cut
75              
76             sub content_remove_indentation {
77 72     72 1 175 my ( $self, $indent ) = @_;
78 72         158 $indent = ' ' x $indent;
79 72         1108 my $content = $self->raw_content;
80 72         766 $content =~ s/^$indent//;
81 72         239 return $content;
82             }
83              
84             =head2 debug_summary
85              
86             Returns a string with the filename and line number
87              
88             =cut
89              
90             sub debug_summary {
91 0     0 1 0 my $self = shift;
92 0         0 my $filename = $self->filename;
93             return
94 0         0 "Input: $filename line "
95             . $self->number . ": ["
96             . $self->raw_content . "]";
97             }
98              
99             =head2 filename
100              
101             Returns either the filename, or the string C<[String]> if the document was
102             loaded from a string
103              
104             =cut
105              
106             sub filename {
107 26     26 1 84 my $self = shift;
108 26 50       427 $self->document->filename || '[String]';
109             }
110              
111             =head2 is_blank
112              
113             =head2 is_comment
114              
115             Return true if the line is either blank, or is a comment.
116              
117             =cut
118              
119 853     853 1 1878 sub is_blank { return !( $_[0]->content =~ m/\S/ ) }
120 1864     1864 1 7029 sub is_comment { return scalar $_[0]->content =~ m/^\s*#/ }
121              
122             sub _strip {
123 5490     5490   32159 my $string = shift;
124 5490         17023 $string =~ s/^\s+//;
125 5490         16005 $string =~ s/\s+$//;
126 5490         24344 return $string;
127             }
128              
129             =head1 AUTHOR
130              
131             Peter Sergeant C
132              
133             =head1 LICENSE
134              
135             Copyright 2019-2023, Erik Huelsmann
136             Copyright 2011-2019, Peter Sergeant; Licensed under the same terms as Perl
137              
138             =cut
139              
140             1;