App/Chart/SymbolMatch.pm

filter: Statementstmt 81.8% 9 / 11 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 86.6% 13 / 15 CC 1 SCAR 0.7
CC
1
Cov
82%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« App/Chart/Manual.pm ↑ Summary App/Chart/Gtk2/Job.pm »
1 # Copyright 2008, 2009, 2010, 2011, 2015, 2016 Kevin Ryde
2  
3 # This file is part of Chart.
4 #
5 # Chart is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 3, or (at your option) any later version.
8 #
9 # Chart is distributed in the hope that it will be useful, but WITHOUT ANY
10 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12 # details.
13 #
14 # You should have received a copy of the GNU General Public License along
15 # with Chart. If not, see <http://www.gnu.org/licenses/>.
16  
17 package App::Chart::SymbolMatch;
18 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 0 ▶use App::Chart;
Subroutine BEGIN: called CC=1 SCAR=2.6
22 use App::Chart::Gtk2::Symlist;
23  
24  
25 sub find {
26 my ($target, $preferred_symlist) = @_;
27 if ($target eq '') { return; }
28 my @symlists = App::Chart::Gtk2::Symlist->all_lists;
29  
30 # elevate $preferred_symlist to first in @symlists
31 if ($preferred_symlist) {
32 @symlists = grep {$_ != $preferred_symlist} @symlists;
33 splice @symlists, 0,0, $preferred_symlist;
34 }
35  
36 # exclude subset lists like "Alerts"
37 # @symlists = grep {! $_->is_subset} @symlists;
38  
39 foreach my $proc (\&eq, \&eq_ci,
40 \&eq_sans_suffix, \&eq_ci_sans_suffix,
41 \&eq_ci_sans_hat,
42 \&prefix_ci_sans_hat) {
43 foreach my $symlist (@symlists) {
44 my $listref = $symlist->symbol_listref;
45 foreach my $symbol (@$listref) {
46 if ($proc->($target, $symbol)) {
47 return ($symbol, $symlist);
48 }
49 }
50 }
51 }
52 return undef;
53 }
54  
55 sub eq {
56 my ($x, $y) = @_;
57 return $x eq $y;
58 }
59 sub eq_ci {
60 my ($x, $y) = @_;
61 return uc($x) eq uc($y);
62 }
63 sub eq_sans_suffix {
64 my ($x, $y) = @_;
65 $x = App::Chart::symbol_sans_suffix ($x);
66 $y = App::Chart::symbol_sans_suffix ($y);
67 return $x eq $y;
68 }
69 sub eq_ci_sans_suffix {
70 my ($x, $y) = @_;
71 $x = App::Chart::symbol_sans_suffix ($x);
72 $y = App::Chart::symbol_sans_suffix ($y);
73 return uc($x) eq uc($y);
74 }
75 sub eq_ci_sans_hat {
76 my ($x, $y) = @_;
77 $x =~ s/^\^//;
78 $y =~ s/^\^//;
79 return uc($x) eq uc($y);
80 }
81 sub prefix_ci_sans_hat {
82 my ($part, $str) = @_;
83 $part =~ s/^\^//;
84 $str =~ s/^\^//;
85 return ($str =~ /^\U\Q$part/);
86 }
87  
88 1;
89 __END__
« App/Chart/Manual.pm ↑ Summary App/Chart/Gtk2/Job.pm »