Changeset 2232
- Timestamp:
- 12/28/08 22:02:48 (3 years ago)
- File:
-
- 1 edited
-
trunk/Padre/lib/Padre/Document/Perl.pm (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Padre/lib/Padre/Document/Perl.pm
r2217 r2232 4 4 use strict; 5 5 use warnings; 6 7 6 use Carp (); 8 7 use Params::Util '_INSTANCE'; … … 22 21 23 22 # TODO watch out! These PPI methods may be VERY expensive! 24 # (Ballpark: Around 1 second of *BLOCKING* CPU per 1000 lines)23 # (Ballpark: Around 1 Gigahertz-second of *BLOCKING* CPU per 1000 lines) 25 24 # Check out Padre::Task::PPI and its subclasses instead! 26 25 sub ppi_get { … … 83 82 } 84 83 85 my $keywords; 86 87 sub keywords { 88 unless ( defined $keywords ) { 89 $keywords = YAML::Tiny::LoadFile( 90 Padre::Util::sharefile( 'languages', 'perl5', 'perl5.yml' ) 91 ); 92 } 93 return $keywords; 94 } 95 96 sub get_functions { 97 my $self = shift; 98 my $text = $self->text_get; 99 100 my %nlCharTable = ( UNIX => "\n", WIN => "\r\n", MAC => "\r" ); 101 my $nlchar = $nlCharTable{ $self->get_newline_type }; 102 103 return $text =~ m/${nlchar}sub\s+(\w+(?:::\w+)*)/g; 104 } 105 106 sub get_function_regex { 107 my ( $self, $sub ) = @_; 108 109 my %nlCharTable = ( UNIX => "\n", WIN => "\r\n", MAC => "\r" ); 110 my $nlchar = $nlCharTable{ $self->get_newline_type }; 111 112 return qr!(?:^|${nlchar})sub\s+$sub\b!; 113 } 114 115 sub get_command { 116 my $self = shift; 117 118 # Check the file name 119 my $filename = $self->filename; 120 # unless ( $filename and $filename =~ /\.pl$/i ) { 121 # die "Only .pl files can be executed\n"; 122 # } 123 124 # Run with the same Perl that launched Padre 125 # TODO: get preferred Perl from configuration 126 my $perl = Padre->perl_interpreter; 127 128 my $dir = File::Basename::dirname($filename); 129 chdir $dir; 130 return qq{"$perl" "$filename"}; 131 } 132 133 sub pre_process { 134 my ( $self ) = @_; 135 my $config = Padre->ide->config; 136 137 if ($config->{editor_perl5_beginner}) { 138 require Padre::Document::Perl::Beginner; 139 my $b = Padre::Document::Perl::Beginner->new; 140 if ($b->check( $self->text_get )) { 141 return 1; 142 } else { 143 $self->set_errstr( $b->error ); 144 return; 145 } 146 } 147 148 return 1; 149 } 84 85 86 87 88 ##################################################################### 89 # Padre::Document GUI Integration 150 90 151 91 sub colorize { … … 282 222 } 283 223 224 225 226 227 228 ##################################################################### 229 # Padre::Document Document Analysis 230 231 my $keywords; 232 233 sub keywords { 234 unless ( defined $keywords ) { 235 $keywords = YAML::Tiny::LoadFile( 236 Padre::Util::sharefile( 'languages', 'perl5', 'perl5.yml' ) 237 ); 238 } 239 return $keywords; 240 } 241 242 sub get_functions { 243 my $self = shift; 244 my $text = $self->text_get; 245 246 my %nlCharTable = ( UNIX => "\n", WIN => "\r\n", MAC => "\r" ); 247 my $nlchar = $nlCharTable{ $self->get_newline_type }; 248 249 return $text =~ m/${nlchar}sub\s+(\w+(?:::\w+)*)/g; 250 } 251 252 sub get_function_regex { 253 my ( $self, $sub ) = @_; 254 255 my %nlCharTable = ( UNIX => "\n", WIN => "\r\n", MAC => "\r" ); 256 my $nlchar = $nlCharTable{ $self->get_newline_type }; 257 258 return qr!(?:^|${nlchar})sub\s+$sub\b!; 259 } 260 261 sub get_command { 262 my $self = shift; 263 264 # Check the file name 265 my $filename = $self->filename; 266 # unless ( $filename and $filename =~ /\.pl$/i ) { 267 # die "Only .pl files can be executed\n"; 268 # } 269 270 # Run with the same Perl that launched Padre 271 # TODO: get preferred Perl from configuration 272 my $perl = Padre->perl_interpreter; 273 274 my $dir = File::Basename::dirname($filename); 275 chdir $dir; 276 return qq{"$perl" "$filename"}; 277 } 278 279 sub pre_process { 280 my ( $self ) = @_; 281 my $config = Padre->ide->config; 282 283 if ($config->{editor_perl5_beginner}) { 284 require Padre::Document::Perl::Beginner; 285 my $b = Padre::Document::Perl::Beginner->new; 286 if ($b->check( $self->text_get )) { 287 return 1; 288 } else { 289 $self->set_errstr( $b->error ); 290 return; 291 } 292 } 293 294 return 1; 295 } 296 284 297 # Checks the syntax of a Perl document. 285 298 # Documented in Padre::Document! … … 417 430 } 418 431 432 433 434 435 436 ##################################################################### 437 # Padre::Document Document Manipulation 438 419 439 sub lexical_variable_replacement { 420 440 my ($self, $replacement) = @_; … … 465 485 my @words; 466 486 push @words ,grep { ! $seen{$_}++ } reverse ($pre_text =~ /$regex/g); 467 push @words , grep { ! $seen{$_}++ } ($post_text =~ /$regex/g);487 push @words ,grep { ! $seen{$_}++ } ($post_text =~ /$regex/g); 468 488 469 489 if (@words > 20) { … … 473 493 return (length($prefix), @words); 474 494 } 475 476 495 477 496 1;
Note: See TracChangeset
for help on using the changeset viewer.
