blib/lib/PPIx/EditorTools/FindUnmatchedBrace.pm

filter: Statementstmt 93.7% 30 / 32 Branchbran 50.0% 1 / 2 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 8 / 8 Podpod 100% 1 / 1 totaltotal 76.9% 40 / 52 CC 4 SCAR 10.8
CC
4
Cov
78%
find
6.4
BEGIN
1.0
BEGIN
1.0
CRAP 3.0
« blib/lib/PPIx/EditorTools/Outline.pm ↑ Summary blib/lib/PPIx/EditorTools/FindVariableDeclaration.pm »
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.21';
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 2 ▶sub find {
Subroutine find: called CC=4 SCAR=18.5
Pod documented
17 2 my ( $self, %args ) = @_;
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
BranchTrueFalseTotal
if ($where) 2 0 2
24 @$where = sort {
25 0 ▶ PPIx::EditorTools::element_depth($b) <=> PPIx::EditorTools::element_depth($a)
Condition0%0/6
PPIx::EditorTools::element_depth($b) <=> PPIx::EditorTools::element_depth($a) || $a->location->[0] <=> $b->location->[0] || $a->location->[1] <=> $b->location->[1]
l!l&&r!l&&!r
000
PPIx::EditorTools::element_depth($b) <=> PPIx::EditorTools::element_depth($a) or $a->location->[0] <=> $b->location->[0]
l!l&&r!l&&!r
000
MC/DC0%0/3
PPIx::EditorTools::element_depth($b) <=> PPIx::EditorTools::element_depth($a) || $a->location->[0] <=> $b->location->[0] || $a->location->[1] <=> $b->location->[1]
PPIx::EditorTools::element_depth($b) <=> PPIx::EditorTools::element_depth($a) $a->location->[0] <=> $b->location->[0] $a->location->[1] <=> $b->location->[1]
Truth table0%0/4
A or B || C
A= PPIx::EditorTools::element_depth($b) <=> PPIx::EditorTools::element_depth($a)B= $a->location->[0] <=> $b->location->[0]C= $a->location->[1] <=> $b->location->[1]
ABCresult
1XX1
01X1
0011
0000
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.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<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__
« blib/lib/PPIx/EditorTools/Outline.pm ↑ Summary blib/lib/PPIx/EditorTools/FindVariableDeclaration.pm »