1package Test::Cukes::Feature;
2use Moose;
3
4use Test::Cukes::Scenario;
5
6has name => (
7    is => "rw",
8    required => 1,
9    isa => "Str"
10);
11
12has body => (
13    is => "rw",
14    isa => "Str"
15);
16
17has scenarios => (
18    is => "rw",
19    isa => "ArrayRef[Test::Cukes::Scenario]"
20);
21
22sub BUILDARGS {
23    my $class = shift;
24    if (@_ == 1 && ! ref $_[0]) {
25        my $text = shift;
26        my $args = {
27            name => "",
28            body => "",
29            scenarios => []
30        };
31        my @blocks = split /\n\n/, $text;
32        my $meta = shift @blocks;
33
34        unless ($meta =~ m/^Feature:\s([^\n]+x?)$(.+)\z/sm) {
35            die "Cannot extra feature name and body from text:\n----\n$meta\n----\n\n";
36        }
37
38        $args->{name} = $1;
39        $args->{body} = $2;
40
41        for my $scenario_text (@blocks) {
42            unless ($scenario_text =~ s/^  (.+?)$/$1/mg) {
43                die "Scenario text is not properly indented:\n----\n${scenario_text}\n----\n\n";
44            }
45            push @{$args->{scenarios}}, Test::Cukes::Scenario->new($scenario_text)
46        }
47
48        return $args;
49    }
50
51    return $class->SUPER::BUILDARGS(@_);
52}
53
54__PACKAGE__->meta->make_immutable;
55no Moose;
561;
57