From: nperez Date: Sun, 9 Aug 2009 00:16:09 +0000 (-0500) Subject: Move strip_attrs which is a purely parsing method down into the base class X-Git-Tag: 0.005009~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9de3c0575dae5881780a79b80867ae983edb7cc9;p=p5sagit%2FDevel-Declare.git Move strip_attrs which is a purely parsing method down into the base class --- diff --git a/lib/Devel/Declare/Context/Simple.pm b/lib/Devel/Declare/Context/Simple.pm index 8cbc8c1..a7e3116 100644 --- a/lib/Devel/Declare/Context/Simple.pm +++ b/lib/Devel/Declare/Context/Simple.pm @@ -189,6 +189,52 @@ sub strip_names_and_args { return \@args; } +sub strip_attrs { + my $self = shift; + $self->skipspace; + + my $linestr = Devel::Declare::get_linestr; + my $attrs = ''; + + if (substr($linestr, $self->offset, 1) eq ':') { + while (substr($linestr, $self->offset, 1) ne '{') { + if (substr($linestr, $self->offset, 1) eq ':') { + substr($linestr, $self->offset, 1) = ''; + Devel::Declare::set_linestr($linestr); + + $attrs .= ':'; + } + + $self->skipspace; + $linestr = Devel::Declare::get_linestr(); + + if (my $len = Devel::Declare::toke_scan_word($self->offset, 0)) { + my $name = substr($linestr, $self->offset, $len); + substr($linestr, $self->offset, $len) = ''; + Devel::Declare::set_linestr($linestr); + + $attrs .= " ${name}"; + + if (substr($linestr, $self->offset, 1) eq '(') { + my $length = Devel::Declare::toke_scan_str($self->offset); + my $arg = Devel::Declare::get_lex_stuff(); + Devel::Declare::clear_lex_stuff(); + $linestr = Devel::Declare::get_linestr(); + substr($linestr, $self->offset, $length) = ''; + Devel::Declare::set_linestr($linestr); + + $attrs .= "(${arg})"; + } + } + } + + $linestr = Devel::Declare::get_linestr(); + } + + return $attrs; +} + + sub get_curstash_name { return Devel::Declare::get_curstash_name; } diff --git a/lib/Devel/Declare/MethodInstaller/Simple.pm b/lib/Devel/Declare/MethodInstaller/Simple.pm index ce7be44..a5f0c37 100644 --- a/lib/Devel/Declare/MethodInstaller/Simple.pm +++ b/lib/Devel/Declare/MethodInstaller/Simple.pm @@ -24,51 +24,6 @@ sub install_methodhandler { ); } -sub strip_attrs { - my $self = shift; - $self->skipspace; - - my $linestr = Devel::Declare::get_linestr; - my $attrs = ''; - - if (substr($linestr, $self->offset, 1) eq ':') { - while (substr($linestr, $self->offset, 1) ne '{') { - if (substr($linestr, $self->offset, 1) eq ':') { - substr($linestr, $self->offset, 1) = ''; - Devel::Declare::set_linestr($linestr); - - $attrs .= ':'; - } - - $self->skipspace; - $linestr = Devel::Declare::get_linestr(); - - if (my $len = Devel::Declare::toke_scan_word($self->offset, 0)) { - my $name = substr($linestr, $self->offset, $len); - substr($linestr, $self->offset, $len) = ''; - Devel::Declare::set_linestr($linestr); - - $attrs .= " ${name}"; - - if (substr($linestr, $self->offset, 1) eq '(') { - my $length = Devel::Declare::toke_scan_str($self->offset); - my $arg = Devel::Declare::get_lex_stuff(); - Devel::Declare::clear_lex_stuff(); - $linestr = Devel::Declare::get_linestr(); - substr($linestr, $self->offset, $length) = ''; - Devel::Declare::set_linestr($linestr); - - $attrs .= "(${arg})"; - } - } - } - - $linestr = Devel::Declare::get_linestr(); - } - - return $attrs; -} - sub code_for { my ($self, $name) = @_;