Changeset 2142


Ignore:
Timestamp:
12/21/08 11:58:45 (3 years ago)
Author:
hjansen
Message:

Added syntax checking capabilities

Location:
trunk/Padre-Plugin-XML
Files:
3 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Padre-Plugin-XML/Build.PL

    r2029 r2142  
    99    dist_version_from   => 'lib/Padre/Plugin/XML.pm', 
    1010    build_requires => { 
    11         'Test::More' => 0, 
    12         'Padre' => '0.21', 
    13         'XML::Tidy' => 0, 
     11        'Test::More'  => 0, 
     12        'Padre'       => '0.21', 
     13        'XML::Tidy'   => 0, 
     14        'XML::LibXML' => '1.025', 
    1415    }, 
    1516    add_to_cleanup      => [ 'Padre-Plugin-XML-*' ], 
    16     create_makefile_pl => 'traditional', 
     17    create_makefile_pl  => 'traditional', 
    1718); 
    1819 
  • trunk/Padre-Plugin-XML/Changes

    r2088 r2142  
    11Revision history for Padre-Plugin-XML 
     2 
     30.03 
     4        added syntax checking capabilities (HJANSEN) 
    25 
    360.02 
  • trunk/Padre-Plugin-XML/MANIFEST

    r2030 r2142  
    11Build.PL 
    22Changes 
     3lib/Padre/Document/XML.pm 
    34lib/Padre/Plugin/XML.pm 
     5lib/Padre/Task/SyntaxChecker/XML.pm 
    46MANIFEST            This list of files 
    57README 
  • trunk/Padre-Plugin-XML/Makefile.PL

    r2030 r2142  
    66          'VERSION_FROM' => 'lib/Padre/Plugin/XML.pm', 
    77          'PREREQ_PM' => { 
    8                            'Padre' => '0.21', 
    9                            'Test::More' => '0', 
    10                            'XML::Tidy' => '0' 
     8                           'Padre'       => '0.21', 
     9                           'Test::More'  => '0', 
     10                           'XML::Tidy'   => '0', 
     11                           'XML::LibXML' => '1.025' 
    1112                         }, 
    1213          'INSTALLDIRS' => 'site', 
  • trunk/Padre-Plugin-XML/lib/Padre/Document/XML.pm

    r2088 r2142  
    77use Padre::Document (); 
    88 
    9 our $VERSION = '0.22'; 
     9our $VERSION = '0.03'; 
    1010our @ISA     = 'Padre::Document'; 
    1111 
     12sub check_syntax { 
     13    my $self  = shift; 
     14    my %args  = @_; 
     15    $args{background} = 0; 
     16    return $self->_check_syntax_internals(\%args); 
     17} 
    1218 
     19sub check_syntax_in_background { 
     20    my $self  = shift; 
     21    my %args  = @_; 
     22    $args{background} = 1; 
     23    return $self->_check_syntax_internals(\%args); 
     24} 
     25 
     26sub _check_syntax_internals { 
     27    my $self = shift; 
     28    my $args = shift; 
     29 
     30    my $text = $self->text_get; 
     31    unless ( defined $text and $text ne '' ) { 
     32        return []; 
     33    } 
     34 
     35    # Do we really need an update? 
     36    require Digest::MD5; 
     37    use Encode qw(encode_utf8); 
     38    my $md5 = Digest::MD5::md5(encode_utf8($text)); 
     39    unless ( $args->{force} ) { 
     40        if ( defined( $self->{last_checked_md5} ) 
     41             && $self->{last_checked_md5} eq $md5 
     42        ) { 
     43            return; 
     44        } 
     45    } 
     46    $self->{last_checked_md5} = $md5; 
     47 
     48    require Padre::Task::SyntaxChecker::XML; 
     49    my $task = Padre::Task::SyntaxChecker::XML->new( 
     50        notebook_page => $self->editor, 
     51        text => $text, 
     52        filename => $self->editor->{Document}->filename, 
     53        ( exists $args->{on_finish} ? (on_finish => $args->{on_finish}) : () ), 
     54    ); 
     55    if ( $args->{background} ) { 
     56        # asynchronous execution (see on_finish hook) 
     57        $task->schedule(); 
     58        return(); 
     59    } 
     60    else { 
     61        # serial execution, returning the result 
     62        return () if $task->prepare() =~ /^break$/; 
     63        $task->run(); 
     64        return $task->{syntax_check}; 
     65    } 
     66} 
    1367 
    14681; 
  • trunk/Padre-Plugin-XML/lib/Padre/Plugin/XML.pm

    r2088 r2142  
    44use strict; 
    55 
    6 our $VERSION = '0.02'; 
     6our $VERSION = '0.03'; 
    77 
    88use base 'Padre::Plugin'; 
     
    4040    if ( $src ) { 
    4141        my $editor = $self->selected_editor; 
    42         $editor->ReplaceSelection( $string ); 
     42        $editor->ReplaceSelection( $string ); 
    4343    } else { 
    4444        $doc->text_set( $string ); 
Note: See TracChangeset for help on using the changeset viewer.