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