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.21';
5 2     2   176602 use 5.008;
  2         13  
6 2     2   8 use strict;
  2         4  
  2         33  
7 2     2   7 use warnings;
  2         3  
  2         56  
8 2     2   8 use Carp;
  2         3  
  2         93  
9              
10 2     2   9 use base 'PPIx::EditorTools';
  2         4  
  2         538  
11 2     2   12 use Class::XSAccessor accessors => {};
  2         4  
  2         12  
12              
13 2     2   247 use PPI;
  2         3  
  2         313  
14              
15              
16             sub find {
17 2     2 1 755 my ( $self, %args ) = @_;
18 2         11 $self->process_doc(%args);
19              
20 2         5 my $ppi = $self->ppi;
21              
22 2         10 my $where = $ppi->find( \&PPIx::EditorTools::find_unmatched_brace );
23 2 50       21 if ($where) {
24             @$where = sort {
25 2 0 0     5 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         11 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.21
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.
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 to process or a string containing
76             the code (which will be converted into a C) to process.
77             Finds the location of unmatched braces. Returns a
78             C with the unmatched brace (a
79             C) available via the C 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.
87             Also see L, L, and L.
88              
89             =head1 AUTHORS
90              
91             =over 4
92              
93             =item *
94              
95             Steffen Mueller C
96              
97             =item *
98              
99             Mark Grimes C
100              
101             =item *
102              
103             Ahmad M. Zawawi
104              
105             =item *
106              
107             Gabor Szabo
108              
109             =item *
110              
111             Yanick Champoux
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__