File Coverage

blib/lib/PPIx/EditorTools/FindUnmatchedBrace.pm
Criterion Covered Total %
statement 27 29 93.1
branch 1 4 25.0
condition 0 3 0.0
subroutine 8 8 100.0
pod 1 1 100.0
total 37 45 82.2


line stmt bran cond sub pod time code
1             package PPIx::EditorTools::FindUnmatchedBrace;
2             our $AUTHORITY = 'cpan:YANICK';
3             # ABSTRACT: PPI-based unmatched-brace-finder
4             $PPIx::EditorTools::FindUnmatchedBrace::VERSION = '0.20';
5 2     2   161401 use 5.008;
  2         14  
6 2     2   10 use strict;
  2         3  
  2         35  
7 2     2   8 use warnings;
  2         4  
  2         49  
8 2     2   8 use Carp;
  2         4  
  2         141  
9              
10 2     2   12 use base 'PPIx::EditorTools';
  2         3  
  2         499  
11 2     2   17 use Class::XSAccessor accessors => {};
  2         5  
  2         16  
12              
13 2     2   272 use PPI;
  2         4  
  2         317  
14              
15              
16             sub find {
17 2     2 1 937 my ( $self, %args ) = @_;
18 2         14 $self->process_doc(%args);
19              
20 2         7 my $ppi = $self->ppi;
21              
22 2         13 my $where = $ppi->find( \&PPIx::EditorTools::find_unmatched_brace );
23 2 50       24 if ($where) {
24             @$where = sort {
25 2 0 0     15 PPIx::EditorTools::element_depth($b) <=> PPIx::EditorTools::element_depth($a)
  0         0  
26             or $a->location->[0] <=> $b->location->[0]
27             or $a->location->[1] <=> $b->location->[1]
28             } @$where;
29              
30 2         15 return PPIx::EditorTools::ReturnObject->new(
31             ppi => $ppi,
32             element => $where->[0]
33             );
34             }
35 0           return;
36             }
37              
38             1;
39              
40             =pod
41              
42             =encoding UTF-8
43              
44             =head1 NAME
45              
46             PPIx::EditorTools::FindUnmatchedBrace - PPI-based unmatched-brace-finder
47              
48             =head1 VERSION
49              
50             version 0.20
51              
52             =head1 SYNOPSIS
53              
54             my $brace = PPIx::EditorTools::FindUnmatchedBrace->new->find(
55             code => "package TestPackage;\nsub x { 1;\n"
56             );
57             my $location = $brace->element->location;
58              
59             =head1 DESCRIPTION
60              
61             Finds the location of unmatched braces in a C<PPI::Document>.
62              
63             =head1 METHODS
64              
65             =over 4
66              
67             =item new()
68              
69             Constructor. Generally shouldn't be called with any arguments.
70              
71             =item find( ppi => PPI::Document $ppi )
72              
73             =item find( code => Str $code )
74              
75             Accepts either a C<PPI::Document> to process or a string containing
76             the code (which will be converted into a C<PPI::Document>) to process.
77             Finds the location of unmatched braces. Returns a
78             C<PPIx::EditorTools::ReturnObject> with the unmatched brace (a
79             C<PPI::Structure::Block>) available via the C<element> accessor.
80             If there is no unmatched brace, returns undef.
81              
82             =back
83              
84             =head1 SEE ALSO
85              
86             This class inherits from C<PPIx::EditorTools>.
87             Also see L<App::EditorTools>, L<Padre>, and L<PPI>.
88              
89             =head1 AUTHORS
90              
91             =over 4
92              
93             =item *
94              
95             Steffen Mueller C<smueller@cpan.org>
96              
97             =item *
98              
99             Mark Grimes C<mgrimes@cpan.org>
100              
101             =item *
102              
103             Ahmad M. Zawawi <ahmad.zawawi@gmail.com>
104              
105             =item *
106              
107             Gabor Szabo <gabor@szabgab.com>
108              
109             =item *
110              
111             Yanick Champoux <yanick@cpan.org>
112              
113             =back
114              
115             =head1 COPYRIGHT AND LICENSE
116              
117             This software is copyright (c) 2017, 2014, 2012 by The Padre development team as listed in Padre.pm..
118              
119             This is free software; you can redistribute it and/or modify it under
120             the same terms as the Perl 5 programming language system itself.
121              
122             =cut
123              
124             __END__
125              
126              
127             # Copyright 2008-2009 The Padre development team as listed in Padre.pm.
128             # LICENSE
129             # This program is free software; you can redistribute it and/or
130             # modify it under the same terms as Perl 5 itself.