| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | =head1 NAME | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | Devel::PerlySense::Document::Api - The methods (and their locations) | 
| 4 |  |  |  |  |  |  | of a package | 
| 5 |  |  |  |  |  |  |  | 
| 6 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | An API is the methods/subs a module/package supports (or in some cases | 
| 9 |  |  |  |  |  |  | _may_ support). | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | =cut | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  |  | 
| 17 | 63 |  |  | 63 |  | 1119 | use strict; | 
|  | 63 |  |  |  |  | 338 |  | 
|  | 63 |  |  |  |  | 1981 |  | 
| 18 | 63 |  |  | 63 |  | 664 | use warnings; | 
|  | 63 |  |  |  |  | 126 |  | 
|  | 63 |  |  |  |  | 2054 |  | 
| 19 | 63 |  |  | 63 |  | 2202 | use utf8; | 
|  | 63 |  |  |  |  | 112 |  | 
|  | 63 |  |  |  |  | 263 |  | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | package Devel::PerlySense::Document::Api; | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  |  | 
| 27 | 63 |  |  | 63 |  | 4579 | use Spiffy -Base; | 
|  | 63 |  |  |  |  | 22555 |  | 
|  | 63 |  |  |  |  | 284 |  | 
| 28 | 63 |  |  | 63 |  | 90891 | use Carp; | 
|  | 63 |  |  | 63 |  | 101 |  | 
|  | 63 |  |  | 63 |  | 1412 |  | 
|  | 63 |  |  |  |  | 209 |  | 
|  | 63 |  |  |  |  | 88 |  | 
|  | 63 |  |  |  |  | 1339 |  | 
|  | 63 |  |  |  |  | 221 |  | 
|  | 63 |  |  |  |  | 72 |  | 
|  | 63 |  |  |  |  | 3286 |  | 
| 29 | 63 |  |  | 63 |  | 254 | use Data::Dumper; | 
|  | 63 |  |  |  |  | 963 |  | 
|  | 63 |  |  |  |  | 3121 |  | 
| 30 |  |  |  |  |  |  |  | 
| 31 | 63 |  |  | 63 |  | 1634 | use Devel::PerlySense::Document; | 
|  | 63 |  |  |  |  | 81 |  | 
|  | 63 |  |  |  |  | 402 |  | 
| 32 | 63 |  |  | 63 |  | 17942 | use Devel::PerlySense::Document::Location; | 
|  | 63 |  |  |  |  | 83 |  | 
|  | 63 |  |  |  |  | 411 |  | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  |  | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | =head1 PROPERTIES | 
| 39 |  |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  | =head2 rhSub | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | Hash ref with (keys: method/sub name; values: Document::Location objects). | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | Default: {} | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | The Location objects have a C<sub> property which is the name of the | 
| 47 |  |  |  |  |  |  | sub. | 
| 48 |  |  |  |  |  |  |  | 
| 49 |  |  |  |  |  |  | =cut | 
| 50 |  |  |  |  |  |  | field "rhSub" => {}; | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  |  | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  |  | 
| 56 |  |  |  |  |  |  | =head1 API METHODS | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  | =head2 new() | 
| 59 |  |  |  |  |  |  |  | 
| 60 |  |  |  |  |  |  | Create new Api object. | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  | =cut | 
| 63 |  |  |  |  |  |  | sub new(@) { | 
| 64 | 120 |  |  | 120 | 1 | 167 | my $pkg = shift; | 
| 65 | 120 |  |  |  |  | 172 | my (%p) = @_; | 
| 66 |  |  |  |  |  |  |  | 
| 67 | 120 |  |  |  |  | 279 | my $self = bless {}, $pkg; | 
| 68 |  |  |  |  |  |  |  | 
| 69 | 120 |  |  |  |  | 213 | return($self); | 
| 70 |  |  |  |  |  |  | } | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  |  | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  | =head2 aNameSubVisible(oPerlySense => $oPs, fileCurrent => $file) | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | Return array with the method/sub names in the interface that are | 
| 79 |  |  |  |  |  |  | visible. | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | A method is invisible if it's a private method in a base class of | 
| 82 |  |  |  |  |  |  | $fileCurrent, outside the current Project, according to | 
| 83 |  |  |  |  |  |  | $oPerlySense. | 
| 84 |  |  |  |  |  |  |  | 
| 85 |  |  |  |  |  |  | =cut | 
| 86 | 4 |  |  | 4 | 1 | 95 | sub aNameSubVisible { | 
| 87 | 4 |  |  |  |  | 20 | my ($oPerlySense, $fileCurrent) = Devel::PerlySense::Util::aNamedArg(["oPerlySense", "fileCurrent"], @_); | 
| 88 |  |  |  |  |  |  |  | 
| 89 | 4 |  |  |  |  | 16 | my $rsSortSub = $self->rsSortSub($fileCurrent); | 
| 90 | 98 |  |  |  |  | 153 | my @aNameSubVisible = | 
| 91 |  |  |  |  |  |  | sort $rsSortSub | 
| 92 | 4 |  |  |  |  | 98 | grep { ! $self->isSubVisible($oPerlySense, $fileCurrent, $_) } | 
| 93 | 4 |  |  |  |  | 11 | keys %{$self->rhSub}; | 
| 94 |  |  |  |  |  |  |  | 
| 95 | 4 |  |  |  |  | 123 | return(@aNameSubVisible); | 
| 96 |  |  |  |  |  |  | } | 
| 97 |  |  |  |  |  |  |  | 
| 98 |  |  |  |  |  |  |  | 
| 99 |  |  |  |  |  |  |  | 
| 100 |  |  |  |  |  |  |  | 
| 101 |  |  |  |  |  |  |  | 
| 102 |  |  |  |  |  |  | =head2 isSubVisible($oPerlySense, $fileCurrent, $nameSub) | 
| 103 |  |  |  |  |  |  |  | 
| 104 |  |  |  |  |  |  | Return true if the Sub name is visibl, else false. | 
| 105 |  |  |  |  |  |  |  | 
| 106 |  |  |  |  |  |  | A sub/method is invisible if it's a private method in a base class of | 
| 107 |  |  |  |  |  |  | $fileCurrent, outside the current Project, according to $oPerlySense. | 
| 108 |  |  |  |  |  |  |  | 
| 109 |  |  |  |  |  |  | =cut | 
| 110 | 98 |  |  | 98 | 1 | 77 | sub isSubVisible { | 
| 111 | 98 |  |  |  |  | 81 | my ($oPerlySense, $fileCurrent, $nameMethod) = @_; | 
| 112 |  |  |  |  |  |  |  | 
| 113 | 98 |  |  |  |  | 2168 | my $file = $self->rhSub->{$_}->file; | 
| 114 | 98 |  | 100 |  |  | 2973 | my $isInvisible = | 
| 115 |  |  |  |  |  |  | #Is it a base class (file ne current file)? | 
| 116 |  |  |  |  |  |  | $file ne $fileCurrent | 
| 117 |  |  |  |  |  |  | #Is it a private method?   ###TODO: Extract to method, then class *::Method->isPrivate | 
| 118 |  |  |  |  |  |  | && $_ =~ /^_/ | 
| 119 |  |  |  |  |  |  | #Is it outside the project? | 
| 120 |  |  |  |  |  |  | && ! $oPerlySense->isFileInProject( | 
| 121 |  |  |  |  |  |  | file => $file, | 
| 122 |  |  |  |  |  |  | fileProjectOf => $fileCurrent, | 
| 123 |  |  |  |  |  |  | ); | 
| 124 |  |  |  |  |  |  |  | 
| 125 | 98 |  |  |  |  | 236 | return $isInvisible; | 
| 126 |  |  |  |  |  |  | } | 
| 127 |  |  |  |  |  |  |  | 
| 128 |  |  |  |  |  |  |  | 
| 129 |  |  |  |  |  |  |  | 
| 130 |  |  |  |  |  |  |  | 
| 131 |  |  |  |  |  |  |  | 
| 132 |  |  |  |  |  |  | =head2 rsSortSub($fileCurrent) | 
| 133 |  |  |  |  |  |  |  | 
| 134 |  |  |  |  |  |  | Return sub ref for sorting sub names of this Api, using the rhSub | 
| 135 |  |  |  |  |  |  | property and given the $fileCurrent. | 
| 136 |  |  |  |  |  |  |  | 
| 137 |  |  |  |  |  |  | =cut | 
| 138 | 4 |  |  | 4 | 1 | 7 | sub rsSortSub { | 
| 139 | 4 |  |  |  |  | 8 | my ($fileCurrent) = @_; | 
| 140 |  |  |  |  |  |  |  | 
| 141 | 4 |  |  |  |  | 275 | my $rhSub = $self->rhSub(); | 
| 142 |  |  |  |  |  |  | return sub { | 
| 143 |  |  |  |  |  |  | ( | 
| 144 |  |  |  |  |  |  | #If unknown location, display it first no matter what | 
| 145 | 373 | 0 | 66 | 373 |  | 12510 | ( ! $rhSub->{$b}->row ) <=> ( ! $rhSub->{$a}->row) | 
|  |  |  | 33 |  |  |  |  | 
|  |  |  | 33 |  |  |  |  | 
|  |  |  | 0 |  |  |  |  | 
| 146 |  |  |  |  |  |  | or # Then alphabetically (case insensitive) | 
| 147 |  |  |  |  |  |  | uc($a) cmp uc($b) | 
| 148 |  |  |  |  |  |  | ) | 
| 149 |  |  |  |  |  |  | || #Display the current file's methods first | 
| 150 |  |  |  |  |  |  | ($rhSub->{$a}->file eq $fileCurrent) <=> ($rhSub->{$b}->file eq $fileCurrent) | 
| 151 |  |  |  |  |  |  | || #then alphabetically | 
| 152 |  |  |  |  |  |  | $rhSub->{$a}->file cmp $rhSub->{$b}->file   ###TODO: inheritance tree | 
| 153 |  |  |  |  |  |  | || # Then the order in the file | 
| 154 |  |  |  |  |  |  | $rhSub->{$a}->row <=> $rhSub->{$b}->row | 
| 155 |  |  |  |  |  |  | || # Then method name alphabetically (case insensitive) (if on the same row) | 
| 156 |  |  |  |  |  |  | uc($a) cmp uc($b) | 
| 157 | 4 |  |  |  |  | 52 | }; | 
| 158 |  |  |  |  |  |  | } | 
| 159 |  |  |  |  |  |  |  | 
| 160 |  |  |  |  |  |  |  | 
| 161 |  |  |  |  |  |  |  | 
| 162 |  |  |  |  |  |  |  | 
| 163 |  |  |  |  |  |  |  | 
| 164 |  |  |  |  |  |  | =head2 parsePackageSetSub(raNodeSub => $raNodeSub, source => $source, oDocument => $oDocument) | 
| 165 |  |  |  |  |  |  |  | 
| 166 |  |  |  |  |  |  | Parse the entire package data, both $source and found method | 
| 167 |  |  |  |  |  |  | nodes. Add both found subs and $raNodeSub to the rhSub property. | 
| 168 |  |  |  |  |  |  |  | 
| 169 |  |  |  |  |  |  | Return 1 or die on errors. | 
| 170 |  |  |  |  |  |  |  | 
| 171 |  |  |  |  |  |  | =cut | 
| 172 | 118 |  |  | 118 | 1 | 132 | sub parsePackageSetSub { | 
| 173 | 118 |  |  |  |  | 481 | my ($raNodeSub, $source, $oDocument) = Devel::PerlySense::Util::aNamedArg(["raNodeSub", "source", "oDocument"], @_); | 
| 174 |  |  |  |  |  |  |  | 
| 175 |  |  |  |  |  |  | #Temporal cohesion: let the sub declarations overwrite the called subs | 
| 176 |  |  |  |  |  |  | #TODO: The called subs shouldn't overwrite sub declarations of a base class | 
| 177 | 118 |  |  |  |  | 385 | $self->parseSourceSetSub(source => $source, oDocument => $oDocument); | 
| 178 |  |  |  |  |  |  |  | 
| 179 | 118 |  |  |  |  | 180 | for my $oNodeSub (@$raNodeSub) { | 
| 180 | 408 |  |  |  |  | 899 | $self->oLocationSetSub(nameSub => $oNodeSub->name, oDocument => $oDocument, oNode => $oNodeSub); | 
| 181 |  |  |  |  |  |  | } | 
| 182 |  |  |  |  |  |  |  | 
| 183 | 118 |  |  |  |  | 181 | return(1); | 
| 184 |  |  |  |  |  |  | } | 
| 185 |  |  |  |  |  |  |  | 
| 186 |  |  |  |  |  |  |  | 
| 187 |  |  |  |  |  |  |  | 
| 188 |  |  |  |  |  |  |  | 
| 189 |  |  |  |  |  |  |  | 
| 190 |  |  |  |  |  |  | =head2 parseSourceSetSub(source => $source, oDocument => $oDocument) | 
| 191 |  |  |  |  |  |  |  | 
| 192 |  |  |  |  |  |  | Parse the $source, looking for $self->method calls, and | 
| 193 |  |  |  |  |  |  | $self->{hash_key}, and add them to the rhSub property. | 
| 194 |  |  |  |  |  |  |  | 
| 195 |  |  |  |  |  |  | Return 1 or die on errors. | 
| 196 |  |  |  |  |  |  |  | 
| 197 |  |  |  |  |  |  | =cut | 
| 198 | 118 |  |  | 118 | 1 | 150 | sub parseSourceSetSub { | 
| 199 | 118 |  |  |  |  | 342 | my ($source, $oDocument) = Devel::PerlySense::Util::aNamedArg(["source", "oDocument"], @_); | 
| 200 |  |  |  |  |  |  |  | 
| 201 |  |  |  |  |  |  | ###TODO: ignore comments, POD | 
| 202 |  |  |  |  |  |  |  | 
| 203 |  |  |  |  |  |  | #Look for $self->method calls | 
| 204 | 118 |  |  |  |  | 1562 | my @aSelfMethod = $source =~ / \$self \s* -> \s* (\w+) /gsx; | 
| 205 |  |  |  |  |  |  |  | 
| 206 |  |  |  |  |  |  | #Look for $self->{property_name} | 
| 207 | 4 |  |  |  |  | 5 | my @aSelfHash = | 
| 208 |  |  |  |  |  |  | #Remove quotes | 
| 209 | 118 |  |  |  |  | 663 | map { s/ ^ (["'])  ( [^\1]* )   \1 $ /$2/x; $_ }  ## no critic | 
|  | 4 |  |  |  |  | 6 |  | 
| 210 |  |  |  |  |  |  | $source =~ | 
| 211 |  |  |  |  |  |  | / | 
| 212 |  |  |  |  |  |  | \$self \s* -> \s* { | 
| 213 |  |  |  |  |  |  | ( | 
| 214 |  |  |  |  |  |  | (?:  " [^"\ ]+ "  ) | 
| 215 |  |  |  |  |  |  | | | 
| 216 |  |  |  |  |  |  | (?:  ' [^'\ ]+ '  ) | 
| 217 |  |  |  |  |  |  | | | 
| 218 |  |  |  |  |  |  | (?:    \w+      ) | 
| 219 |  |  |  |  |  |  | ) | 
| 220 |  |  |  |  |  |  | /gsx; | 
| 221 |  |  |  |  |  |  |  | 
| 222 | 118 |  |  |  |  | 122 | my %hSeen; | 
| 223 | 118 |  |  |  |  | 263 | for my $method ( grep { ! $hSeen{$_} ++ }  @aSelfMethod, @aSelfHash ) { | 
|  | 818 |  |  |  |  | 1264 |  | 
| 224 | 343 |  |  |  |  | 555 | $self->oLocationSetSub(nameSub => $method, oDocument => $oDocument); | 
| 225 |  |  |  |  |  |  | } | 
| 226 |  |  |  |  |  |  |  | 
| 227 | 118 |  |  |  |  | 342 | return(1); | 
| 228 |  |  |  |  |  |  | } | 
| 229 |  |  |  |  |  |  |  | 
| 230 |  |  |  |  |  |  |  | 
| 231 |  |  |  |  |  |  |  | 
| 232 |  |  |  |  |  |  |  | 
| 233 |  |  |  |  |  |  |  | 
| 234 |  |  |  |  |  |  | =head2 oLocationSetSub(nameSub => $nameSub, oDocument => $oDocument, [oNode => $oNode]) | 
| 235 |  |  |  |  |  |  |  | 
| 236 |  |  |  |  |  |  | Set the $self->rhSub->{$nameSub} to a new Document::Location with | 
| 237 |  |  |  |  |  |  | $oDocument and possibly a row/col for $oNode. Set the rhProperty for: | 
| 238 |  |  |  |  |  |  |  | 
| 239 |  |  |  |  |  |  | sub | 
| 240 |  |  |  |  |  |  |  | 
| 241 |  |  |  |  |  |  | If no $oNode is passed, the location is supposed to be unknown, with | 
| 242 |  |  |  |  |  |  | row/col: 0/0. | 
| 243 |  |  |  |  |  |  |  | 
| 244 |  |  |  |  |  |  | Return the new oLocation. Die on errors. | 
| 245 |  |  |  |  |  |  |  | 
| 246 |  |  |  |  |  |  | =cut | 
| 247 | 757 |  |  | 757 | 1 | 9652 | sub oLocationSetSub { | 
| 248 | 757 |  |  |  |  | 2611 | my ($nameSub, $oDocument) = Devel::PerlySense::Util::aNamedArg(["nameSub", "oDocument"], @_); | 
| 249 | 757 |  |  |  |  | 1622 | my %p = @_;  my ($oNode) = ($p{oNode}); | 
|  | 757 |  |  |  |  | 687 |  | 
| 250 |  |  |  |  |  |  |  | 
| 251 | 757 |  |  |  |  | 489 | my $oLocation; | 
| 252 |  |  |  |  |  |  |  | 
| 253 | 757 | 100 |  |  |  | 1176 | if($oNode) { | 
| 254 | 411 |  |  |  |  | 737 | $oLocation = $oDocument->oLocationOfNode($oNode); | 
| 255 |  |  |  |  |  |  | } else { | 
| 256 | 346 |  |  |  |  | 9359 | $oLocation = Devel::PerlySense::Document::Location->new( | 
| 257 |  |  |  |  |  |  | file => $oDocument->file, | 
| 258 |  |  |  |  |  |  | ); | 
| 259 |  |  |  |  |  |  | } | 
| 260 |  |  |  |  |  |  |  | 
| 261 | 757 |  |  |  |  | 20330 | $oLocation->rhProperty->{sub} = $nameSub; | 
| 262 | 757 |  |  |  |  | 25052 | $self->rhSub->{$nameSub} = $oLocation; | 
| 263 |  |  |  |  |  |  |  | 
| 264 | 757 |  |  |  |  | 4610 | return($oLocation); | 
| 265 |  |  |  |  |  |  | } | 
| 266 |  |  |  |  |  |  |  | 
| 267 |  |  |  |  |  |  |  | 
| 268 |  |  |  |  |  |  |  | 
| 269 |  |  |  |  |  |  |  | 
| 270 |  |  |  |  |  |  |  | 
| 271 |  |  |  |  |  |  | =head2 mergeWithBase($oApiBase) | 
| 272 |  |  |  |  |  |  |  | 
| 273 |  |  |  |  |  |  | Adjust this object by adding appropriate parts of $oApiBase, i.e. the | 
| 274 |  |  |  |  |  |  | methods in $oApiBase->rhSub that aren't overridden in this class. | 
| 275 |  |  |  |  |  |  |  | 
| 276 |  |  |  |  |  |  | If a method has no row/col in neither base or self, it's supposed to | 
| 277 |  |  |  |  |  |  | be defined in the base class. Any method definition with row/col in | 
| 278 |  |  |  |  |  |  | self overrides one in base. | 
| 279 |  |  |  |  |  |  |  | 
| 280 |  |  |  |  |  |  | Return 1 on success. Die on errors. | 
| 281 |  |  |  |  |  |  |  | 
| 282 |  |  |  |  |  |  | =cut | 
| 283 | 21 |  |  | 21 | 1 | 38 | sub mergeWithBase { | 
| 284 | 21 |  |  |  |  | 29 | my ($oApiBase) = @_; | 
| 285 |  |  |  |  |  |  |  | 
| 286 | 21 |  |  |  |  | 516 | my $rhSub = $self->rhSub; | 
| 287 | 21 |  |  |  |  | 100 | while(my ($method, $oLocationBase) = each %{$oApiBase->rhSub}) { | 
|  | 236 |  |  |  |  | 6299 |  | 
| 288 |  |  |  |  |  |  |  | 
| 289 | 215 | 100 |  |  |  | 1201 | if(my $oLocation = $rhSub->{$method}) { | 
| 290 |  |  |  |  |  |  |  | 
| 291 |  |  |  |  |  |  | #If both are just seen as $self->X, go with the base one | 
| 292 | 105 | 100 | 100 |  |  | 2489 | if($oLocation->row == 0 && $oLocationBase->row == 0) {   #TODO: refactor: ! hasPosition | 
| 293 | 69 |  |  |  |  | 1979 | $rhSub->{$method} = $oLocationBase; | 
| 294 |  |  |  |  |  |  | } | 
| 295 |  |  |  |  |  |  |  | 
| 296 |  |  |  |  |  |  | #If the base one is a real declaration and self is only seen as $self->X, go with the base one | 
| 297 | 105 | 100 | 100 |  |  | 5265 | if($oLocationBase->row != 0 && $oLocation->row == 0) { | 
| 298 | 14 |  |  |  |  | 433 | $rhSub->{$method} = $oLocationBase; | 
| 299 |  |  |  |  |  |  | } | 
| 300 |  |  |  |  |  |  |  | 
| 301 |  |  |  |  |  |  | } else { | 
| 302 |  |  |  |  |  |  | #Not present in self, copy from base | 
| 303 | 110 |  |  |  |  | 192 | $rhSub->{$method} = $oLocationBase; | 
| 304 |  |  |  |  |  |  | } | 
| 305 |  |  |  |  |  |  | } | 
| 306 |  |  |  |  |  |  |  | 
| 307 | 21 |  |  |  |  | 125 | return(1); | 
| 308 |  |  |  |  |  |  | } | 
| 309 |  |  |  |  |  |  |  | 
| 310 |  |  |  |  |  |  |  | 
| 311 |  |  |  |  |  |  |  | 
| 312 |  |  |  |  |  |  |  | 
| 313 |  |  |  |  |  |  |  | 
| 314 |  |  |  |  |  |  | =head2 isSubSupported($nameSub) | 
| 315 |  |  |  |  |  |  |  | 
| 316 |  |  |  |  |  |  | Return true if $nameSub is supported by this API, else false. | 
| 317 |  |  |  |  |  |  |  | 
| 318 |  |  |  |  |  |  | =cut | 
| 319 | 114 |  |  | 114 | 1 | 95 | sub isSubSupported { | 
| 320 | 114 |  |  |  |  | 118 | my ($nameSub) = @_; | 
| 321 | 114 |  |  |  |  | 2751 | return( exists $self->rhSub->{$nameSub} ); | 
| 322 |  |  |  |  |  |  | } | 
| 323 |  |  |  |  |  |  |  | 
| 324 |  |  |  |  |  |  |  | 
| 325 |  |  |  |  |  |  |  | 
| 326 |  |  |  |  |  |  |  | 
| 327 |  |  |  |  |  |  |  | 
| 328 |  |  |  |  |  |  | =head2 percentSupportedOf($raNameSub) | 
| 329 |  |  |  |  |  |  |  | 
| 330 |  |  |  |  |  |  | Return percent (0..100) of how many of the sub names in raNameSub that | 
| 331 |  |  |  |  |  |  | are present in the api. | 
| 332 |  |  |  |  |  |  |  | 
| 333 |  |  |  |  |  |  | =cut | 
| 334 | 16 |  |  | 16 | 1 | 31 | sub percentSupportedOf { | 
| 335 | 16 |  |  |  |  | 23 | my ($raNameSub) = @_; | 
| 336 |  |  |  |  |  |  |  | 
| 337 | 16 |  |  |  |  | 18 | my $countSupported = grep { $self->isSubSupported($_) } @$raNameSub; | 
|  | 68 |  |  |  |  | 292 |  | 
| 338 | 16 |  | 100 |  |  | 125 | my $percent = $countSupported / (scalar(@$raNameSub) || 1); | 
| 339 |  |  |  |  |  |  |  | 
| 340 | 16 |  |  |  |  | 77 | return($percent * 100); | 
| 341 |  |  |  |  |  |  | } | 
| 342 |  |  |  |  |  |  |  | 
| 343 |  |  |  |  |  |  |  | 
| 344 |  |  |  |  |  |  |  | 
| 345 |  |  |  |  |  |  |  | 
| 346 |  |  |  |  |  |  |  | 
| 347 |  |  |  |  |  |  | =head2 percentConsistsOf($raNameSub) | 
| 348 |  |  |  |  |  |  |  | 
| 349 |  |  |  |  |  |  | Return percent (0..100) of how much of the api consists of the sub | 
| 350 |  |  |  |  |  |  | names in raNameSub. | 
| 351 |  |  |  |  |  |  |  | 
| 352 |  |  |  |  |  |  | I.e. a large API will have a low percentage. Extra sub names in | 
| 353 |  |  |  |  |  |  | $raNameSub will not affect the percentage. | 
| 354 |  |  |  |  |  |  |  | 
| 355 |  |  |  |  |  |  | =cut | 
| 356 | 19 |  |  | 19 | 1 | 20 | sub percentConsistsOf { | 
| 357 | 19 |  |  |  |  | 22 | my ($raNameSub) = @_; | 
| 358 |  |  |  |  |  |  |  | 
| 359 | 19 |  |  |  |  | 27 | my %hNameSub = map { $_ => 1 } @$raNameSub; | 
|  | 78 |  |  |  |  | 195 |  | 
| 360 | 19 |  |  |  |  | 37 | my $countConsists = grep { $hNameSub{$_} } keys %{$self->rhSub}; | 
|  | 251 |  |  |  |  | 308 |  | 
|  | 19 |  |  |  |  | 481 |  | 
| 361 | 19 |  | 50 |  |  | 32 | my $percent = $countConsists / (scalar(keys %{$self->rhSub}) || 1); | 
| 362 |  |  |  |  |  |  |  | 
| 363 | 19 |  |  |  |  | 153 | return($percent * 100); | 
| 364 |  |  |  |  |  |  | } | 
| 365 |  |  |  |  |  |  |  | 
| 366 |  |  |  |  |  |  |  | 
| 367 |  |  |  |  |  |  |  | 
| 368 |  |  |  |  |  |  |  | 
| 369 |  |  |  |  |  |  |  | 
| 370 |  |  |  |  |  |  | 1; | 
| 371 |  |  |  |  |  |  |  | 
| 372 |  |  |  |  |  |  |  | 
| 373 |  |  |  |  |  |  |  | 
| 374 |  |  |  |  |  |  |  | 
| 375 |  |  |  |  |  |  |  | 
| 376 |  |  |  |  |  |  | __END__ | 
| 377 |  |  |  |  |  |  |  | 
| 378 |  |  |  |  |  |  | =encoding utf8 | 
| 379 |  |  |  |  |  |  |  | 
| 380 |  |  |  |  |  |  | =head1 AUTHOR | 
| 381 |  |  |  |  |  |  |  | 
| 382 |  |  |  |  |  |  | Johan Lindström, C<< <johanl[ÄT]DarSerMan.com> >> | 
| 383 |  |  |  |  |  |  |  | 
| 384 |  |  |  |  |  |  | =head1 BUGS | 
| 385 |  |  |  |  |  |  |  | 
| 386 |  |  |  |  |  |  | Please report any bugs or feature requests to | 
| 387 |  |  |  |  |  |  | C<bug-devel-perlysense@rt.cpan.org>, or through the web interface at | 
| 388 |  |  |  |  |  |  | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Devel-PerlySense>. | 
| 389 |  |  |  |  |  |  | I will be notified, and then you'll automatically be notified of progress on | 
| 390 |  |  |  |  |  |  | your bug as I make changes. | 
| 391 |  |  |  |  |  |  |  | 
| 392 |  |  |  |  |  |  | =head1 ACKNOWLEDGEMENTS | 
| 393 |  |  |  |  |  |  |  | 
| 394 |  |  |  |  |  |  | =head1 COPYRIGHT & LICENSE | 
| 395 |  |  |  |  |  |  |  | 
| 396 |  |  |  |  |  |  | Copyright 2005 Johan Lindström, All Rights Reserved. | 
| 397 |  |  |  |  |  |  |  | 
| 398 |  |  |  |  |  |  | This program is free software; you can redistribute it and/or modify it | 
| 399 |  |  |  |  |  |  | under the same terms as Perl itself. | 
| 400 |  |  |  |  |  |  |  | 
| 401 |  |  |  |  |  |  | =cut |