Ticket #401: fix_moose_attr_eval_ppix_outline.patch
| File fix_moose_attr_eval_ppix_outline.patch, 2.7 KB (added by buff3r, 13 months ago) |
|---|
-
PPIx-EditorTools/lib/PPIx/EditorTools/Outline.pm
100 100 if grep { $thing->module eq $_ } ( 101 101 'Method::Signatures', 102 102 'MooseX::Declare', 103 'MooseX::Method::Signatures' 103 'MooseX::Method::Signatures', 104 'Moose' 104 105 ); 105 106 } 106 107 } … … 135 136 $_[1]->next_sibling->isa('PPI::Token::Whitespace') or return 0; 136 137 my $sib_content = $_[1]->next_sibling->next_sibling->content or return 0; 137 138 138 $sib_content =~ m/^\b(\w+)\b/; 139 return 0 unless defined $1; 139 my $name = eval $sib_content; 140 141 # if eval() failed for whatever reason, default to original trimmed original token 142 $name ||= ($sib_content =~ m/^\b(\w+)\b/)[0]; 143 144 return 0 unless defined $name; 140 145 141 146 # test for MooseX::Declare class, role 142 147 if ( $_[1]->content =~ m/(class|role)/ ) { 143 148 $self->_Moo_PkgName( $cur_pkg, $sib_content, $_[1] ); 144 return 1; # break out so we don't write Packa e name as method149 return 1; # break out so we don't write Package name as method 145 150 } 146 151 147 push @{ $cur_pkg->{methods} }, { name => $ 1, line => $_[1]->line_number };152 push @{ $cur_pkg->{methods} }, { name => $name, line => $_[1]->line_number }; 148 153 149 154 return 1; 150 155 } … … 168 173 ######## 169 174 sub _Moo_Attributes { 170 175 my ( $self, $ma_node2, $ma_cur_pkg, $ma_thing ) = @_; 171 176 177 my $line_num = $ma_thing->location->[0]; 178 172 179 # tidy up Moose attributes for Outline display 173 my $ma_has_att = $ma_node2->content; 174 my $space = q{ }; 175 $ma_has_att =~ s/^\[?(qw(\/|\())?$space?//; # remove leading 'quote word' 176 $ma_has_att =~ s/(\/|\))?\]?$//; # remove traling 'quote word' 177 $ma_has_att =~ s/(\'$space?)//g; # remove Single-Quoted String Literals 178 $ma_has_att =~ s/($space?\,$space?)/$space/g; # remove commers add space 179 # split mulitline attributes to one per line 180 my @ma_atts_found = split /$space/, $ma_has_att,; 181 182 foreach my $ma_att (@ma_atts_found) { 183 184 # add to outline 185 push @{ $ma_cur_pkg->{attributes} }, { name => $ma_att, line => $ma_thing->location->[0] }; 186 } 187 return; 180 my $attrs = eval $ma_node2->content; 181 182 # if eval() failed for whatever reason, default to original token 183 $attrs ||= $ma_node2->content; 184 185 (ref $attrs eq 'ARRAY') ? 186 map { 187 push @{ $ma_cur_pkg->{attributes} }, 188 { name => $_, line => $line_num } 189 } grep { defined } @{ $attrs } 190 : 191 push @{ $ma_cur_pkg->{attributes} }, { name => $attrs, line => $line_num }; 188 192 } 189 193 190 194 ########
