NAME

Data::Table::Gherkin - Lean Gherkin data table parser

SYNOPSIS

use Data::Table::Gherkin ();

my $self = Data::Table::Gherkin->parse( <<'GDT', { has_header => 1 } );
| firstName   | lastName | birthDate  |
| Annie M. G. | Schmidt  | 1911-05-20 |
| Roald       | Dahl     | 1916-09-13 |
| Astrid      | Lindgren | 1907-11-14 |
GDT

# or

my $self = CLASS->parse( \*DATA, { has_header => 1 } );

for my $row ( @{ $self->rows } ) {
...
}

__DATA__
| firstName   | lastName | birthDate  |
| Annie M. G. | Schmidt  | 1911-05-20 |
| Roald       | Dahl     | 1916-09-13 |
| Astrid      | Lindgren | 1907-11-14 |

DESCRIPTION

This class provides a Gherkin data table parser. The parse() factory method (a class method) does the parsing. It has one required argument. This argument is either the string representation of a data table or it is a readable filehandle that in paragraph mode ($/ is set to '') returns the string representation of a data table on each read. The last method argument is an optional hash reference. The has_header key has to have a boolean value. You will set it, if the data table has a header row. This has an impact on the data structure returned by the rows() object method. On success the parse() method returns an object of this class; otherwise it carps on error and returns an undef value.

The rows() object method returns an array reference. The array elements are hash references if the data table has a header row (has_header is true); otherwise the array elements are array references.

If you want to use a newline character in a data table column, you can write this as \n. If you need a | as part of the column, you can escape it as \|. And finally, if you need a \, you can escape that with \\.

SEE ALSO

AUTHOR

Sven Willenbuecher <sven.willenbuecher@gmx.de>

COPYRIGHT AND LICENSE

This software is copyright (c) 2026 by Sven Willenbuecher.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.