| 1 | package PPIx::EditorTools::FindUnmatchedBrace; | ||||||||||||||||||||||||||||
| 2 | 3 | our $AUTHORITY = 'cpan:YANICK'; | |||||||||||||||||||||||||||
| 3 | # ABSTRACT: PPI-based unmatched-brace-finder | ||||||||||||||||||||||||||||
| 4 | 3 | $PPIx::EditorTools::FindUnmatchedBrace::VERSION = '0.20'; | |||||||||||||||||||||||||||
| 5 | 3 | ▶ | use 5.008; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use base 'PPIx::EditorTools'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use Class::XSAccessor accessors => {}; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use PPI; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | sub find { | ||||||||||||||||||||||||||||
| 17 | 2 | ▶ | my ( $self, %args ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
find: called CC=4 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 18 | 2 | $self->process_doc(%args); | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 2 | my $ppi = $self->ppi; | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 2 | my $where = $ppi->find( \&PPIx::EditorTools::find_unmatched_brace ); | |||||||||||||||||||||||||||
| 23 | 2 | ▶ | if ($where) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | @$where = sort { | ||||||||||||||||||||||||||||
| 25 | 2 | ▶ | PPIx::EditorTools::element_depth($b) <=> PPIx::EditorTools::element_depth($a) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
PPIx::EditorTools::element_depth($b) <=> PPIx::EditorTools::element_depth($a) or $a->location->[0] <=> $b->location->[0]
MC/DC0%0/2
PPIx::EditorTools::element_depth($b) <=> PPIx::EditorTools::element_depth($a) or $a->location->[0] <=> $b->location->[0]
PPIx::EditorTools::element_depth($b) <=> PPIx::EditorTools::element_depth($a)
$a->location->[0] <=> $b->location->[0]
Truth table0%0/3
A or B
A= PPIx::EditorTools::element_depth($b) <=> PPIx::EditorTools::element_depth($a)B= $a->location->[0] <=> $b->location->[0]
| |||||||||||||||||||||||||||||
| 26 | or $a->location->[0] <=> $b->location->[0] | ||||||||||||||||||||||||||||
| 27 | or $a->location->[1] <=> $b->location->[1] | ||||||||||||||||||||||||||||
| 28 | } @$where; | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 2 | return PPIx::EditorTools::ReturnObject->new( | |||||||||||||||||||||||||||
| 31 | ppi => $ppi, | ||||||||||||||||||||||||||||
| 32 | element => $where->[0] | ||||||||||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | 0 | return; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 3 | 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. | ||||||||||||||||||||||||||||