Commit | Line | Data |
8d66ec34 |
1 | use MooseX::Declare; |
2 | |
3 | role CatalystX::Declare::Context::StringParsing { |
4 | |
5 | use Devel::Declare; |
6 | |
8d66ec34 |
7 | method rest_of_line { |
8 | |
9 | $self->skipspace; |
10 | |
11 | my $linestr = $self->get_linestr; |
12 | my $left = substr $linestr, $self->offset; |
13 | |
14 | return $left; |
15 | } |
16 | |
17 | method strip_from_linestr (Int $chars) { |
18 | |
19 | my $linestr = $self->get_linestr; |
20 | substr($linestr, $self->offset, $chars) = ''; |
21 | $self->set_linestr($linestr); |
22 | } |
23 | |
24 | method get_string { |
25 | |
26 | my $left = $self->rest_of_line; |
27 | |
4960c7ec |
28 | # only work on allowed types of string declarations |
8d66ec34 |
29 | if ($left =~ /^"/ and my $num = Devel::Declare::toke_scan_str $self->offset) { |
30 | |
31 | my $found = Devel::Declare::get_lex_stuff; |
32 | Devel::Declare::clear_lex_stuff; |
33 | |
34 | $self->strip_from_linestr($num); |
35 | |
36 | return qq{"$found"}; |
37 | } |
4960c7ec |
38 | |
39 | # check for a scalar version if nothing found |
8d66ec34 |
40 | else { |
41 | return $self->get_scalar; |
42 | } |
43 | } |
44 | |
45 | method get_scalar { |
46 | |
47 | my $left = $self->rest_of_line; |
48 | |
4960c7ec |
49 | # only allow simple scalars |
8d66ec34 |
50 | if ($left =~ s/^ ( \$ [a-z_] [a-z0-9_]* ) //ix) { |
51 | |
52 | my $found = $1; |
53 | |
54 | $self->strip_from_linestr( length $found ); |
55 | |
56 | return qq{"$found"}; |
57 | } |
4960c7ec |
58 | |
59 | # nothing suitable found |
8d66ec34 |
60 | else { |
61 | return undef; |
62 | } |
63 | } |
64 | } |