| 1 | package Hash::Search; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | require Exporter; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 1 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 1 | our $VERSION = '0.03'; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 1 | my %hash_search_result = (); | |||||||||||||||||||||||||||
| 14 | 1 | my $hash_search_result_count = 0; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 1 | ▶ | sub new{ | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | # new: create a new instance of | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 1 | my $class = shift; | |||||||||||||||||||||||||||
| 21 | 1 | my $self = {}; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 1 | return bless($self, $class); | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 5 | ▶ | sub hash_search{ | ||||||||||||||||||||||||||
|
Subroutine
hash_search: called CC=7 SCAR=20.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | # hash_search: Find matches of names using the regular expression | ||||||||||||||||||||||||||||
| 30 | # and hash given. | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 5 | my $class = shift; | |||||||||||||||||||||||||||
| 33 | 5 | my ($passed_hash, %passed_hash); | |||||||||||||||||||||||||||
| 34 | 5 | my $passed_expression; | |||||||||||||||||||||||||||
| 35 | 5 | my $regex_test = ""; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 5 | $passed_expression = shift; | |||||||||||||||||||||||||||
| 38 | 5 | (%passed_hash) = @_; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | # Check if the hash or the expression passed is blank and | ||||||||||||||||||||||||||||
| 41 | # write a carp message if blank. | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 5 | ▶ | if (!%passed_hash){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 0 | carp("The hash given is blank"); | |||||||||||||||||||||||||||
| 45 | 0 | return; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 5 | ▶ | if (!$passed_expression || $passed_expression eq ""){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $passed_expression or $passed_expression eq ""
MC/DC0%0/2
not $passed_expression or $passed_expression eq ""
not $passed_expression
$passed_expression eq ""
Truth table33%1/3
not(A) or B
A= not $passed_expressionB= $passed_expression eq ""
| |||||||||||||||||||||||||||||
| 49 | 0 | carp("The expression given is blank"); | |||||||||||||||||||||||||||
| 50 | 0 | return; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | # Process the hash given putting the results into a | ||||||||||||||||||||||||||||
| 54 | # seperate hash while increment the search result | ||||||||||||||||||||||||||||
| 55 | # counter. | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 5 | %hash_search_result = (); | |||||||||||||||||||||||||||
| 58 | 5 | $hash_search_result_count = 0; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 5 | foreach my $hash_key (keys %passed_hash){ | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 25 | ▶ | if ($hash_key =~ m/$passed_expression/){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | # We have a match so put the result into the hash. | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 7 | $hash_search_result{ $hash_key } = $passed_hash{$hash_key}; | |||||||||||||||||||||||||||
| 67 | 7 | $hash_search_result_count++; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | # Return 1 if there was at least one search result returned and return | ||||||||||||||||||||||||||||
| 73 | # 0 if not. | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 5 | ▶ | return 1 if $hash_search_result_count >= 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 1 | return 0; | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 7 | ▶ | sub hash_search_resultdata{ | ||||||||||||||||||||||||||
|
Subroutine
hash_search_resultdata: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | # hash_search_resultdata: Return the result data for | ||||||||||||||||||||||||||||
| 83 | # the search that has been made. | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 7 | return %hash_search_result; | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 6 | ▶ | sub hash_search_resultcount{ | ||||||||||||||||||||||||||
|
Subroutine
hash_search_resultcount: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | # hash_search_resultcount: Return the count of results | ||||||||||||||||||||||||||||
| 92 | # for the search. | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 6 | return $hash_search_result_count; | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 1 | 1; | |||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | __END__ | ||||||||||||||||||||||||||||