~ubuntu-branches/ubuntu/wily/padre/wily

« back to all changes in this revision

Viewing changes to lib/Padre/Task/PPI/FindVariableDeclaration.pm

  • Committer: Bazaar Package Importer
  • Author(s): Damyan Ivanov
  • Date: 2009-08-12 14:44:55 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20090812144455-yvk90oa92khfcnls
Tags: 0.42-1
* New Upstream Version
  + add explicit dependency on libtest-simple-perl (>= 0.88)
  + rules: use dh --with quilt (and bump quilt build-dependency to 0.46-7)
  + rules: no need to re-generate .mo files from .po. Upstream does it now
  + copyright: describe share/icons/padre/16x16/logo.png
    - describe share/icons/padre/16x16/toggle-comments.png
    - Padre license is the same as Perl (i.e. not Perl 5)
    - update list of copright holders
    - also list translators
  + drop libtest-most-perl from build-dependencies
  + add liblocale-msgfmt-perl to build-dependencies
  + add libcapture-tiny-perl to (build-)dependencies
  + add libfile-remove-perl (>= 1.42) to (build-)dependencies
  + drop libmodule-inspector-perl from (build-)dependencies
  + add libppix-editortools-perl to (build-)dependencies
  + add libparse-exuberantctags-perl to (build-)dependencies
  + patches:
    - drop lower-wx-requirement-to-2.8.7.patch and replace it with
      SKIP_WXWIDGETS_VERSION_CHECK=1 when configuring
      adjust README.debian accordingly
    - refresh disable-tcp-server.patch
    - drop don't-require-new-file-path.patch (applied upstream)
    - rework fix-pod2-errors.patch (new release, new errors :))
* add fix-perl-interpreter-path.patch fixing the path to the perl interpreter
  in three examples (thanks lintian)
* add more lintian overrides about script-not-executable for scripts that are
  treated as examples/templates
* add fix-whatis.patch fixing the whatis entry of Padre::Wx
* add menu and .desktop file

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
use warnings;
5
5
use Padre::Wx ();
6
6
 
7
 
our $VERSION = '0.36';
 
7
our $VERSION = '0.42';
8
8
 
9
9
use base 'Padre::Task::PPI';
 
10
use PPIx::EditorTools::FindVariableDeclaration;
10
11
 
11
12
=pod
12
13
 
16
17
 
17
18
=head1 SYNOPSIS
18
19
 
19
 
  # finds declaration of varibable at cursor
 
20
  # finds declaration of variable at cursor
20
21
  my $declfinder = Padre::Task::PPI::FindVariableDeclaration->new(
21
22
          document => $document_obj,
22
23
          location => [$line, $column], # ppi-style location is okay, too
43
44
        delete $self->{document};
44
45
        if ( not defined $mto->{document} ) {
45
46
                require Carp;
46
 
                Carp::croak("Missing Padre::Document::Perl object as {document} attribute of the brace-finder task");
 
47
                Carp::croak("Missing Padre::Document::Perl object as {document} attribute of the FindVariableDeclaration task");
47
48
        }
48
49
 
49
50
        if ( not defined $self->{location} ) {
59
60
        my $ppi      = shift or return;
60
61
        my $location = $self->{location};
61
62
 
62
 
        # TODO: PPI bug? This shouldn't be necessary!
63
 
        require Padre::PPI;
64
 
        $ppi->flush_locations;
65
 
        my $token = Padre::PPI::find_token_at_location( $ppi, $location );
66
 
        if ( not $token ) {
67
 
                $self->{error} = "no token";
 
63
        my $declaration = eval {
 
64
                PPIx::EditorTools::FindVariableDeclaration->new->find(
 
65
                        ppi    => $ppi,
 
66
                        line   => $location->[0],
 
67
                        column => $location->[1]
 
68
                );
 
69
        };
 
70
        if ($@) {
 
71
                $self->{error} = $@;
68
72
                return;
69
73
        }
70
74
 
71
 
        my $declaration = Padre::PPI::find_variable_declaration($token);
72
 
        if ( not defined $declaration ) {
73
 
                $self->{error} = "no declaration";
74
 
                return;
75
 
        }
76
 
        $self->{declaration_location} = $declaration->location;
 
75
        $self->{declaration_location} = $declaration->element->location;
77
76
        return ();
78
77
}
79
78
 
85
84
                $self->{main_thread_only}->{document}->ppi_select( $self->{declaration_location} );
86
85
        } else {
87
86
                my $text;
88
 
                if ( $self->{error} eq 'no token' ) {
 
87
                if ( $self->{error} =~ /no token/ ) {
89
88
                        $text = Wx::gettext("Current cursor does not seem to point at a variable");
90
 
                } elsif ( $self->{error} eq 'no declaration' ) {
 
89
                } elsif ( $self->{error} =~ /no declaration/ ) {
91
90
                        $text = Wx::gettext("No declaration could be found for the specified (lexical?) variable");
92
91
                } else {
93
92
                        $text = Wx::gettext("Unknown error");
94
93
                }
95
94
                Wx::MessageBox(
96
 
                        $text,
97
 
                        Wx::gettext("Check Canceled"),
98
 
                        Wx::wxOK,
99
 
                        Padre->ide->wx->main
 
95
                        $text,    Wx::gettext("Search Canceled"),
 
96
                        Wx::wxOK, Padre->ide->wx->main
100
97
                );
101
98
        }
102
99
        return ();