| 1 | package Parse::Functions; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 6 | our $VERSION = '0.01'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | Parse::Functions - list all the functions in source code | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | See L<Parse::Functions::Perl> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 16 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 16 | my ($class) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 16 | my $self = bless {}, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 16 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 15 | ▶ | sub sort_functions { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sort_functions: called CC=16 SCAR=32.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 15 | my ($self, $functions, $order) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 15 | ▶ | return $functions if not $order; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 10 | my @sorted; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # Sort it appropriately | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 10 | ▶ | if ( $order eq 'alphabetical' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | # Alphabetical (aka 'abc') | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # Ignore case and leading non-word characters | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 5 | my @expected = (); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 5 | my @unknown = (); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 5 | foreach my $function (@$functions) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 33 | ▶ | if ( $function =~ /^([^a-zA-Z0-9]*)(.*)$/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 33 | push @expected, [ $function, $1, lc($2) ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | push @unknown, $function; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 33 | @expected = map { $_->[0] } sort { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 5 | ▶ | $a->[2] cmp $b->[2] | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition44%4/9
$Parse::Functions::a->[2] cmp $Parse::Functions::b->[2] || length $Parse::Functions::a->[1] <=> length $Parse::Functions::b->[1] || $Parse::Functions::a->[1] cmp $Parse::Functions::b->[1] || $Parse::Functions::a->[0] cmp $Parse::Functions::b->[0]
$Parse::Functions::a->[2] cmp $Parse::Functions::b->[2] or length $Parse::Functions::a->[1] <=> length $Parse::Functions::b->[1] or $Parse::Functions::a->[1] cmp $Parse::Functions::b->[1]
$Parse::Functions::a->[2] cmp $Parse::Functions::b->[2] or length $Parse::Functions::a->[1] <=> length $Parse::Functions::b->[1]
MC/DC0%0/4
$Parse::Functions::a->[2] cmp $Parse::Functions::b->[2] || length $Parse::Functions::a->[1] <=> length $Parse::Functions::b->[1] || $Parse::Functions::a->[1] cmp $Parse::Functions::b->[1] || $Parse::Functions::a->[0] cmp $Parse::Functions::b->[0]
$Parse::Functions::a->[2] cmp $Parse::Functions::b->[2]
length $Parse::Functions::a->[1] <=> length $Parse::Functions::b->[1]
$Parse::Functions::a->[1] cmp $Parse::Functions::b->[1]
$Parse::Functions::a->[0] cmp $Parse::Functions::b->[0]
Truth table40%2/5
A or B or C || D
A= $Parse::Functions::a->[2] cmp $Parse::Functions::b->[2]B= length $Parse::Functions::a->[1] <=> length $Parse::Functions::b->[1]C= $Parse::Functions::a->[1] cmp $Parse::Functions::b->[1]D= $Parse::Functions::a->[0] cmp $Parse::Functions::b->[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | || length( $a->[1] ) <=> length( $b->[1] ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | || $a->[1] cmp $b->[1] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | || $a->[0] cmp $b->[0] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | } @expected; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | @unknown = | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | sort { lc($a) cmp lc($b) || $a cmp $b } @unknown; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
lc $a cmp lc $b || $a cmp $b
MC/DC0%0/2
lc $a cmp lc $b || $a cmp $b
lc $a cmp lc $b
$a cmp $b
Truth table0%0/3
A || B
A= lc $a cmp lc $bB= $a cmp $b
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 5 | @sorted = ( @expected, @unknown ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | } elsif ( $order eq 'alphabetical_private_last' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | # As above, but with private functions last | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 5 | my @expected = (); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 5 | my @unknown = (); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 5 | foreach my $function (@$functions) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 33 | ▶ | if ( $function =~ /^([^a-zA-Z0-9]*)(.*)$/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 33 | push @expected, [ $function, $1, lc($2) ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | push @unknown, $function; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 33 | @expected = map { $_->[0] } sort { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 5 | ▶ | length( $a->[1] ) <=> length( $b->[1] ) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition55%5/9
length $Parse::Functions::a->[1] <=> length $Parse::Functions::b->[1] || $Parse::Functions::a->[1] cmp $Parse::Functions::b->[1] || $Parse::Functions::a->[2] cmp $Parse::Functions::b->[2] || $Parse::Functions::a->[0] cmp $Parse::Functions::b->[0]
length $Parse::Functions::a->[1] <=> length $Parse::Functions::b->[1] or $Parse::Functions::a->[1] cmp $Parse::Functions::b->[1] or $Parse::Functions::a->[2] cmp $Parse::Functions::b->[2]
length $Parse::Functions::a->[1] <=> length $Parse::Functions::b->[1] or $Parse::Functions::a->[1] cmp $Parse::Functions::b->[1]
MC/DC0%0/4
length $Parse::Functions::a->[1] <=> length $Parse::Functions::b->[1] || $Parse::Functions::a->[1] cmp $Parse::Functions::b->[1] || $Parse::Functions::a->[2] cmp $Parse::Functions::b->[2] || $Parse::Functions::a->[0] cmp $Parse::Functions::b->[0]
length $Parse::Functions::a->[1] <=> length $Parse::Functions::b->[1]
$Parse::Functions::a->[1] cmp $Parse::Functions::b->[1]
$Parse::Functions::a->[2] cmp $Parse::Functions::b->[2]
$Parse::Functions::a->[0] cmp $Parse::Functions::b->[0]
Truth table40%2/5
A or B or C || D
A= length $Parse::Functions::a->[1] <=> length $Parse::Functions::b->[1]B= $Parse::Functions::a->[1] cmp $Parse::Functions::b->[1]C= $Parse::Functions::a->[2] cmp $Parse::Functions::b->[2]D= $Parse::Functions::a->[0] cmp $Parse::Functions::b->[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | || $a->[1] cmp $b->[1] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | || $a->[2] cmp $b->[2] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | || $a->[0] cmp $b->[0] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } @expected; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | @unknown = | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | sort { lc($a) cmp lc($b) || $a cmp $b } @unknown; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
lc $a cmp lc $b || $a cmp $b
MC/DC0%0/2
lc $a cmp lc $b || $a cmp $b
lc $a cmp lc $b
$a cmp $b
Truth table0%0/3
A || B
A= lc $a cmp lc $bB= $a cmp $b
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 5 | @sorted = ( @expected, @unknown ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 10 | return \@sorted; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | # recognize newline even if encoding is not the platform default (will not work for MacOS classic) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 15 | ▶ | sub newline { qr{\cM?\cJ} }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
newline: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 16 | ▶ | sub find { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 16 | my ($self, $text, $sort) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | # Show an empty function list by default | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 16 | ▶ | return () if not $text; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 15 | my $function_re = $self->function_re; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 15 | my @functions = grep { defined $_ } $text =~ /$function_re/g; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 15 | return @{ $self->sort_functions( \@functions, $sort ) }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 6 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | # Copyright 2008-2014 The Padre development team as listed in Padre.pm. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | # LICENSE | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | # This program is free software; you can redistribute it and/or | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | # modify it under the same terms as Perl 5 itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||