sub init {
my $self = shift;
@{$self}{ qw(Declarator Offset) } = @_;
- $self;
+ return $self;
}
-sub offset : lvalue { shift->{Offset}; }
-sub declarator { shift->{Declarator} }
+sub offset {
+ my $self = shift;
+ return $self->{Offset}
+}
+
+sub inc_offset {
+ my $self = shift;
+ $self->{Offset} += shift;
+}
+
+sub declarator {
+ my $self = shift;
+ return $self->{Declarator}
+}
sub skip_declarator {
my $self = shift;
- $self->offset += Devel::Declare::toke_move_past_token( $self->offset );
+ $self->inc_offset(Devel::Declare::toke_move_past_token($self->offset));
}
sub skipspace {
my $self = shift;
- $self->offset += Devel::Declare::toke_skipspace( $self->offset );
+ $self->inc_offset(Devel::Declare::toke_skipspace($self->offset));
}
sub get_linestr {
}
sub shadow {
- my $self = shift;
+ my $self = shift;
my $pack = $self->get_curstash_name;
Devel::Declare::shadow_sub( $pack . '::' . $self->declarator, $_[0] );
}
my $self = shift;
$self->skipspace;
- my $Offset = $self->offset;
my $linestr = Devel::Declare::get_linestr;
my $attrs = '';
- if (substr($linestr, $Offset, 1) eq ':') {
- while (substr($linestr, $Offset, 1) ne '{') {
- if (substr($linestr, $Offset, 1) eq ':') {
- substr($linestr, $Offset, 1) = '';
+ 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;
- $Offset = $self->offset;
$linestr = Devel::Declare::get_linestr();
- if (my $len = Devel::Declare::toke_scan_word($Offset, 0)) {
- my $name = substr($linestr, $Offset, $len);
- substr($linestr, $Offset, $len) = '';
+ 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, $Offset, 1) eq '(') {
- my $length = Devel::Declare::toke_scan_str($Offset);
+ 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, $Offset, $length) = '';
+ substr($linestr, $self->offset, $length) = '';
Devel::Declare::set_linestr($linestr);
$attrs .= "(${arg})";
@test_list = (method { 1 }, sub { 2 }, method () { 3 }, sub { 4 });
- method leftie :lvalue { $self->{attributes} };
+ method leftie($left) : method { $self->{left} ||= $left; $self->{left} };
}
use Test::More 'no_plan';
is($o->main, 'main', 'declaration of package named method ok');
-$o->leftie = 'attributes work';
+$o->leftie( 'attributes work' );
is($o->leftie, 'attributes work', 'code attributes intact');
$o->upgrade;