Changeset 2232


Ignore:
Timestamp:
12/28/08 22:02:48 (3 years ago)
Author:
adamk
Message:

Starting Padre::Document refactoring by reorganising the methods into sections.

Padre::Document->setup was doing nothing, merge it back into new

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Padre/lib/Padre/Document/Perl.pm

    r2217 r2232  
    44use strict; 
    55use warnings; 
    6  
    76use Carp            (); 
    87use Params::Util    '_INSTANCE'; 
     
    2221 
    2322# 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) 
    2524# Check out Padre::Task::PPI and its subclasses instead! 
    2625sub ppi_get { 
     
    8382} 
    8483 
    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 
    15090 
    15191sub colorize { 
     
    282222} 
    283223 
     224 
     225 
     226 
     227 
     228##################################################################### 
     229# Padre::Document Document Analysis 
     230 
     231my $keywords; 
     232 
     233sub 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 
     242sub 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 
     252sub 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 
     261sub 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 
     279sub 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 
    284297# Checks the syntax of a Perl document. 
    285298# Documented in Padre::Document! 
     
    417430} 
    418431 
     432 
     433 
     434 
     435 
     436##################################################################### 
     437# Padre::Document Document Manipulation 
     438 
    419439sub lexical_variable_replacement { 
    420440    my ($self, $replacement) = @_; 
     
    465485    my @words; 
    466486    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); 
    468488 
    469489    if (@words > 20) { 
     
    473493    return (length($prefix), @words); 
    474494} 
    475  
    476495 
    4774961; 
Note: See TracChangeset for help on using the changeset viewer.