| 1 | package Venus::Role::Mappable; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 33 | ▶ | use 5.018; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 33 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 33 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | # IMPORTS | ||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 33 | ▶ | use Venus::Role 'fault'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | # AUDITS | ||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 60 | ▶ | sub AUDIT { | ||||||||||||||||||
|
Subroutine
AUDIT: called CC=20 SCAR=41.9
Pod
undocumented
| |||||||||||||||||||||
| 15 | 60 | my ($self, $from) = @_; | |||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | 60 | ▶ | my $name = ref $self || $self; | ||||||||||||||||||
|
Condition33%1/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table33%1/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 60 | ▶ | if (!$from->can('all')) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 20 | 0 | fault "${from} requires 'all' to consume ${name}"; | |||||||||||||||||||
| 21 | } | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 60 | ▶ | if (!$from->can('any')) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 24 | 0 | fault "${from} requires 'any' to consume ${name}"; | |||||||||||||||||||
| 25 | } | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | 60 | ▶ | if (!$from->can('call')) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 28 | 0 | fault "${from} requires 'call' to consume ${name}"; | |||||||||||||||||||
| 29 | } | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 60 | ▶ | if (!$from->can('count')) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 32 | 0 | fault "${from} requires 'count' to consume ${name}"; | |||||||||||||||||||
| 33 | } | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 60 | ▶ | if (!$from->can('delete')) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 36 | 0 | fault "${from} requires 'delete' to consume ${name}"; | |||||||||||||||||||
| 37 | } | ||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | 60 | ▶ | if (!$from->can('each')) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 40 | 0 | fault "${from} requires 'each' to consume ${name}"; | |||||||||||||||||||
| 41 | } | ||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | 60 | ▶ | if (!$from->can('empty')) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 44 | 0 | fault "${from} requires 'empty' to consume ${name}"; | |||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | 60 | ▶ | if (!$from->can('exists')) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 48 | 0 | fault "${from} requires 'exists' to consume ${name}"; | |||||||||||||||||||
| 49 | } | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | 60 | ▶ | if (!$from->can('grep')) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 52 | 0 | fault "${from} requires 'grep' to consume ${name}"; | |||||||||||||||||||
| 53 | } | ||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 60 | ▶ | if (!$from->can('iterator')) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 56 | 0 | fault "${from} requires 'iterator' to consume ${name}"; | |||||||||||||||||||
| 57 | } | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | 60 | ▶ | if (!$from->can('keys')) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 60 | 0 | fault "${from} requires 'keys' to consume ${name}"; | |||||||||||||||||||
| 61 | } | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | 60 | ▶ | if (!$from->can('map')) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 64 | 0 | fault "${from} requires 'map' to consume ${name}"; | |||||||||||||||||||
| 65 | } | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | 60 | ▶ | if (!$from->can('none')) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 68 | 0 | fault "${from} requires 'none' to consume ${name}"; | |||||||||||||||||||
| 69 | } | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | 60 | ▶ | if (!$from->can('one')) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 72 | 0 | fault "${from} requires 'one' to consume ${name}"; | |||||||||||||||||||
| 73 | } | ||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | 60 | ▶ | if (!$from->can('pairs')) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 76 | 0 | fault "${from} requires 'pairs' to consume ${name}"; | |||||||||||||||||||
| 77 | } | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | 60 | ▶ | if (!$from->can('random')) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 80 | 0 | fault "${from} requires 'random' to consume ${name}"; | |||||||||||||||||||
| 81 | } | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | 60 | ▶ | if (!$from->can('reverse')) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 84 | 0 | fault "${from} requires 'reverse' to consume ${name}"; | |||||||||||||||||||
| 85 | } | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | 60 | ▶ | if (!$from->can('slice')) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 88 | 0 | fault "${from} requires 'slice' to consume ${name}"; | |||||||||||||||||||
| 89 | } | ||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | 60 | return $self; | |||||||||||||||||||
| 92 | } | ||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | 33 | 1; | |||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | =head1 NAME | ||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | Venus::Role::Mappable - Mappable Role | ||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | =cut | ||||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | =head1 ABSTRACT | ||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | Mappable Role for Perl 5 | ||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | =cut | ||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | =head1 SYNOPSIS | ||||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | package Example; | ||||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | use Venus::Class; | ||||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | with 'Venus::Role::Mappable'; | ||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | sub all; | ||||||||||||||||||||
| 119 | sub any; | ||||||||||||||||||||
| 120 | sub call; | ||||||||||||||||||||
| 121 | sub count; | ||||||||||||||||||||
| 122 | sub delete; | ||||||||||||||||||||
| 123 | sub each; | ||||||||||||||||||||
| 124 | sub empty; | ||||||||||||||||||||
| 125 | sub exists; | ||||||||||||||||||||
| 126 | sub grep; | ||||||||||||||||||||
| 127 | sub iterator; | ||||||||||||||||||||
| 128 | sub keys; | ||||||||||||||||||||
| 129 | sub map; | ||||||||||||||||||||
| 130 | sub none; | ||||||||||||||||||||
| 131 | sub one; | ||||||||||||||||||||
| 132 | sub pairs; | ||||||||||||||||||||
| 133 | sub random; | ||||||||||||||||||||
| 134 | sub reverse; | ||||||||||||||||||||
| 135 | sub slice; | ||||||||||||||||||||
| 136 | |||||||||||||||||||||
| 137 | package main; | ||||||||||||||||||||
| 138 | |||||||||||||||||||||
| 139 | my $example = Example->new; | ||||||||||||||||||||
| 140 | |||||||||||||||||||||
| 141 | # $example->random; | ||||||||||||||||||||
| 142 | |||||||||||||||||||||
| 143 | =cut | ||||||||||||||||||||
| 144 | |||||||||||||||||||||
| 145 | =head1 DESCRIPTION | ||||||||||||||||||||
| 146 | |||||||||||||||||||||
| 147 | This package provides a specification for the consuming package to implement | ||||||||||||||||||||
| 148 | methods that makes the object mappable. See L<Venus::Array> and L<Venus::Hash> | ||||||||||||||||||||
| 149 | as other examples of mappable classes. | ||||||||||||||||||||
| 150 | |||||||||||||||||||||
| 151 | =cut | ||||||||||||||||||||
| 152 | |||||||||||||||||||||
| 153 | =head1 METHODS | ||||||||||||||||||||
| 154 | |||||||||||||||||||||
| 155 | This package provides the following methods: | ||||||||||||||||||||
| 156 | |||||||||||||||||||||
| 157 | =cut | ||||||||||||||||||||
| 158 | |||||||||||||||||||||
| 159 | =head2 all | ||||||||||||||||||||
| 160 | |||||||||||||||||||||
| 161 | all(coderef $code) (boolean) | ||||||||||||||||||||
| 162 | |||||||||||||||||||||
| 163 | The all method should return true if the callback returns true for all of the | ||||||||||||||||||||
| 164 | elements provided. | ||||||||||||||||||||
| 165 | |||||||||||||||||||||
| 166 | I<Since C<0.01>> | ||||||||||||||||||||
| 167 | |||||||||||||||||||||
| 168 | =over 4 | ||||||||||||||||||||
| 169 | |||||||||||||||||||||
| 170 | =item all example 1 | ||||||||||||||||||||
| 171 | |||||||||||||||||||||
| 172 | # given: synopsis; | ||||||||||||||||||||
| 173 | |||||||||||||||||||||
| 174 | my $all = $example->all(sub { | ||||||||||||||||||||
| 175 | # ... | ||||||||||||||||||||
| 176 | }); | ||||||||||||||||||||
| 177 | |||||||||||||||||||||
| 178 | =back | ||||||||||||||||||||
| 179 | |||||||||||||||||||||
| 180 | =cut | ||||||||||||||||||||
| 181 | |||||||||||||||||||||
| 182 | =head2 any | ||||||||||||||||||||
| 183 | |||||||||||||||||||||
| 184 | any(coderef $code) (boolean) | ||||||||||||||||||||
| 185 | |||||||||||||||||||||
| 186 | The any method should return true if the callback returns true for any of the | ||||||||||||||||||||
| 187 | elements provided. | ||||||||||||||||||||
| 188 | |||||||||||||||||||||
| 189 | |||||||||||||||||||||
| 190 | |||||||||||||||||||||
| 191 | |||||||||||||||||||||
| 192 | I<Since C<0.01>> | ||||||||||||||||||||
| 193 | |||||||||||||||||||||
| 194 | =over 4 | ||||||||||||||||||||
| 195 | |||||||||||||||||||||
| 196 | =item any example 1 | ||||||||||||||||||||
| 197 | |||||||||||||||||||||
| 198 | # given: synopsis; | ||||||||||||||||||||
| 199 | |||||||||||||||||||||
| 200 | my $any = $example->any(sub { | ||||||||||||||||||||
| 201 | # ... | ||||||||||||||||||||
| 202 | }); | ||||||||||||||||||||
| 203 | |||||||||||||||||||||
| 204 | =back | ||||||||||||||||||||
| 205 | |||||||||||||||||||||
| 206 | =cut | ||||||||||||||||||||
| 207 | |||||||||||||||||||||
| 208 | =head2 count | ||||||||||||||||||||
| 209 | |||||||||||||||||||||
| 210 | count() (number) | ||||||||||||||||||||
| 211 | |||||||||||||||||||||
| 212 | The count method should return the number of top-level element in the data | ||||||||||||||||||||
| 213 | structure. | ||||||||||||||||||||
| 214 | |||||||||||||||||||||
| 215 | |||||||||||||||||||||
| 216 | |||||||||||||||||||||
| 217 | |||||||||||||||||||||
| 218 | I<Since C<0.01>> | ||||||||||||||||||||
| 219 | |||||||||||||||||||||
| 220 | =over 4 | ||||||||||||||||||||
| 221 | |||||||||||||||||||||
| 222 | =item count example 1 | ||||||||||||||||||||
| 223 | |||||||||||||||||||||
| 224 | # given: synopsis; | ||||||||||||||||||||
| 225 | |||||||||||||||||||||
| 226 | my $count = $example->count; | ||||||||||||||||||||
| 227 | |||||||||||||||||||||
| 228 | =back | ||||||||||||||||||||
| 229 | |||||||||||||||||||||
| 230 | =cut | ||||||||||||||||||||
| 231 | |||||||||||||||||||||
| 232 | =head2 delete | ||||||||||||||||||||
| 233 | |||||||||||||||||||||
| 234 | delete(string $key) (any) | ||||||||||||||||||||
| 235 | |||||||||||||||||||||
| 236 | The delete method returns should remove the item in the data structure based on | ||||||||||||||||||||
| 237 | the key provided, returning the item. | ||||||||||||||||||||
| 238 | |||||||||||||||||||||
| 239 | |||||||||||||||||||||
| 240 | |||||||||||||||||||||
| 241 | |||||||||||||||||||||
| 242 | I<Since C<0.01>> | ||||||||||||||||||||
| 243 | |||||||||||||||||||||
| 244 | =over 4 | ||||||||||||||||||||
| 245 | |||||||||||||||||||||
| 246 | =item delete example 1 | ||||||||||||||||||||
| 247 | |||||||||||||||||||||
| 248 | # given: synopsis; | ||||||||||||||||||||
| 249 | |||||||||||||||||||||
| 250 | my $delete = $example->delete(...); | ||||||||||||||||||||
| 251 | |||||||||||||||||||||
| 252 | =back | ||||||||||||||||||||
| 253 | |||||||||||||||||||||
| 254 | =cut | ||||||||||||||||||||
| 255 | |||||||||||||||||||||
| 256 | =head2 each | ||||||||||||||||||||
| 257 | |||||||||||||||||||||
| 258 | each(coderef $code) (arrayref) | ||||||||||||||||||||
| 259 | |||||||||||||||||||||
| 260 | The each method should execute the callback for each item in the data structure | ||||||||||||||||||||
| 261 | passing the key and value as arguments. | ||||||||||||||||||||
| 262 | |||||||||||||||||||||
| 263 | |||||||||||||||||||||
| 264 | |||||||||||||||||||||
| 265 | |||||||||||||||||||||
| 266 | I<Since C<0.01>> | ||||||||||||||||||||
| 267 | |||||||||||||||||||||
| 268 | =over 4 | ||||||||||||||||||||
| 269 | |||||||||||||||||||||
| 270 | =item each example 1 | ||||||||||||||||||||
| 271 | |||||||||||||||||||||
| 272 | # given: synopsis; | ||||||||||||||||||||
| 273 | |||||||||||||||||||||
| 274 | my $results = $example->each(sub { | ||||||||||||||||||||
| 275 | # ... | ||||||||||||||||||||
| 276 | }); | ||||||||||||||||||||
| 277 | |||||||||||||||||||||
| 278 | =back | ||||||||||||||||||||
| 279 | |||||||||||||||||||||
| 280 | =cut | ||||||||||||||||||||
| 281 | |||||||||||||||||||||
| 282 | =head2 empty | ||||||||||||||||||||
| 283 | |||||||||||||||||||||
| 284 | empty() (Value) | ||||||||||||||||||||
| 285 | |||||||||||||||||||||
| 286 | The empty method should drop all items from the data structure. | ||||||||||||||||||||
| 287 | |||||||||||||||||||||
| 288 | |||||||||||||||||||||
| 289 | |||||||||||||||||||||
| 290 | |||||||||||||||||||||
| 291 | I<Since C<0.01>> | ||||||||||||||||||||
| 292 | |||||||||||||||||||||
| 293 | =over 4 | ||||||||||||||||||||
| 294 | |||||||||||||||||||||
| 295 | =item empty example 1 | ||||||||||||||||||||
| 296 | |||||||||||||||||||||
| 297 | # given: synopsis; | ||||||||||||||||||||
| 298 | |||||||||||||||||||||
| 299 | my $empty = $example->empty; | ||||||||||||||||||||
| 300 | |||||||||||||||||||||
| 301 | =back | ||||||||||||||||||||
| 302 | |||||||||||||||||||||
| 303 | =cut | ||||||||||||||||||||
| 304 | |||||||||||||||||||||
| 305 | =head2 exists | ||||||||||||||||||||
| 306 | |||||||||||||||||||||
| 307 | exists(string $key) (boolean) | ||||||||||||||||||||
| 308 | |||||||||||||||||||||
| 309 | The exists method should return true if the item at the key specified exists, | ||||||||||||||||||||
| 310 | otherwise it returns false. | ||||||||||||||||||||
| 311 | |||||||||||||||||||||
| 312 | |||||||||||||||||||||
| 313 | |||||||||||||||||||||
| 314 | |||||||||||||||||||||
| 315 | I<Since C<0.01>> | ||||||||||||||||||||
| 316 | |||||||||||||||||||||
| 317 | =over 4 | ||||||||||||||||||||
| 318 | |||||||||||||||||||||
| 319 | =item exists example 1 | ||||||||||||||||||||
| 320 | |||||||||||||||||||||
| 321 | # given: synopsis; | ||||||||||||||||||||
| 322 | |||||||||||||||||||||
| 323 | my $exists = $example->exists(...); | ||||||||||||||||||||
| 324 | |||||||||||||||||||||
| 325 | =back | ||||||||||||||||||||
| 326 | |||||||||||||||||||||
| 327 | =cut | ||||||||||||||||||||
| 328 | |||||||||||||||||||||
| 329 | =head2 grep | ||||||||||||||||||||
| 330 | |||||||||||||||||||||
| 331 | grep(coderef $code) (arrayref) | ||||||||||||||||||||
| 332 | |||||||||||||||||||||
| 333 | The grep method should execute a callback for each item in the array, passing | ||||||||||||||||||||
| 334 | the value as an argument, returning a value containing the items for which the | ||||||||||||||||||||
| 335 | returned true. | ||||||||||||||||||||
| 336 | |||||||||||||||||||||
| 337 | |||||||||||||||||||||
| 338 | |||||||||||||||||||||
| 339 | |||||||||||||||||||||
| 340 | I<Since C<0.01>> | ||||||||||||||||||||
| 341 | |||||||||||||||||||||
| 342 | =over 4 | ||||||||||||||||||||
| 343 | |||||||||||||||||||||
| 344 | =item grep example 1 | ||||||||||||||||||||
| 345 | |||||||||||||||||||||
| 346 | # given: synopsis; | ||||||||||||||||||||
| 347 | |||||||||||||||||||||
| 348 | my $results = $example->grep(sub { | ||||||||||||||||||||
| 349 | # ... | ||||||||||||||||||||
| 350 | }); | ||||||||||||||||||||
| 351 | |||||||||||||||||||||
| 352 | =back | ||||||||||||||||||||
| 353 | |||||||||||||||||||||
| 354 | =cut | ||||||||||||||||||||
| 355 | |||||||||||||||||||||
| 356 | =head2 iterator | ||||||||||||||||||||
| 357 | |||||||||||||||||||||
| 358 | iterator() (coderef) | ||||||||||||||||||||
| 359 | |||||||||||||||||||||
| 360 | The iterator method should return a code reference which can be used to iterate | ||||||||||||||||||||
| 361 | over the data structure. Each time the iterator is executed it will return the | ||||||||||||||||||||
| 362 | next item in the data structure until all items have been seen, at which point | ||||||||||||||||||||
| 363 | the iterator will return an undefined value. | ||||||||||||||||||||
| 364 | |||||||||||||||||||||
| 365 | |||||||||||||||||||||
| 366 | |||||||||||||||||||||
| 367 | |||||||||||||||||||||
| 368 | I<Since C<0.01>> | ||||||||||||||||||||
| 369 | |||||||||||||||||||||
| 370 | =over 4 | ||||||||||||||||||||
| 371 | |||||||||||||||||||||
| 372 | =item iterator example 1 | ||||||||||||||||||||
| 373 | |||||||||||||||||||||
| 374 | # given: synopsis; | ||||||||||||||||||||
| 375 | |||||||||||||||||||||
| 376 | my $iterator = $example->iterator; | ||||||||||||||||||||
| 377 | |||||||||||||||||||||
| 378 | =back | ||||||||||||||||||||
| 379 | |||||||||||||||||||||
| 380 | =cut | ||||||||||||||||||||
| 381 | |||||||||||||||||||||
| 382 | =head2 keys | ||||||||||||||||||||
| 383 | |||||||||||||||||||||
| 384 | keys() (arrayref) | ||||||||||||||||||||
| 385 | |||||||||||||||||||||
| 386 | The keys method should return an array reference consisting of the keys of the | ||||||||||||||||||||
| 387 | data structure. | ||||||||||||||||||||
| 388 | |||||||||||||||||||||
| 389 | |||||||||||||||||||||
| 390 | |||||||||||||||||||||
| 391 | |||||||||||||||||||||
| 392 | I<Since C<0.01>> | ||||||||||||||||||||
| 393 | |||||||||||||||||||||
| 394 | =over 4 | ||||||||||||||||||||
| 395 | |||||||||||||||||||||
| 396 | =item keys example 1 | ||||||||||||||||||||
| 397 | |||||||||||||||||||||
| 398 | # given: synopsis; | ||||||||||||||||||||
| 399 | |||||||||||||||||||||
| 400 | my $keys = $example->keys; | ||||||||||||||||||||
| 401 | |||||||||||||||||||||
| 402 | =back | ||||||||||||||||||||
| 403 | |||||||||||||||||||||
| 404 | =cut | ||||||||||||||||||||
| 405 | |||||||||||||||||||||
| 406 | =head2 map | ||||||||||||||||||||
| 407 | |||||||||||||||||||||
| 408 | map(coderef $code) (arrayref) | ||||||||||||||||||||
| 409 | |||||||||||||||||||||
| 410 | The map method should iterate over each item in the data structure, executing | ||||||||||||||||||||
| 411 | the code reference supplied in the argument, passing the routine the value at | ||||||||||||||||||||
| 412 | the current position in the loop and returning an array reference containing | ||||||||||||||||||||
| 413 | the items for which the argument returns a value or non-empty list. | ||||||||||||||||||||
| 414 | |||||||||||||||||||||
| 415 | |||||||||||||||||||||
| 416 | |||||||||||||||||||||
| 417 | |||||||||||||||||||||
| 418 | I<Since C<0.01>> | ||||||||||||||||||||
| 419 | |||||||||||||||||||||
| 420 | =over 4 | ||||||||||||||||||||
| 421 | |||||||||||||||||||||
| 422 | =item map example 1 | ||||||||||||||||||||
| 423 | |||||||||||||||||||||
| 424 | # given: synopsis; | ||||||||||||||||||||
| 425 | |||||||||||||||||||||
| 426 | my $results = $example->map(sub { | ||||||||||||||||||||
| 427 | # ... | ||||||||||||||||||||
| 428 | }); | ||||||||||||||||||||
| 429 | |||||||||||||||||||||
| 430 | =back | ||||||||||||||||||||
| 431 | |||||||||||||||||||||
| 432 | =cut | ||||||||||||||||||||
| 433 | |||||||||||||||||||||
| 434 | =head2 none | ||||||||||||||||||||
| 435 | |||||||||||||||||||||
| 436 | none(coderef $code) (boolean) | ||||||||||||||||||||
| 437 | |||||||||||||||||||||
| 438 | The none method should return true if none of the items in the data structure | ||||||||||||||||||||
| 439 | meet the criteria set by the operand and rvalue. | ||||||||||||||||||||
| 440 | |||||||||||||||||||||
| 441 | |||||||||||||||||||||
| 442 | |||||||||||||||||||||
| 443 | |||||||||||||||||||||
| 444 | I<Since C<0.01>> | ||||||||||||||||||||
| 445 | |||||||||||||||||||||
| 446 | =over 4 | ||||||||||||||||||||
| 447 | |||||||||||||||||||||
| 448 | =item none example 1 | ||||||||||||||||||||
| 449 | |||||||||||||||||||||
| 450 | # given: synopsis; | ||||||||||||||||||||
| 451 | |||||||||||||||||||||
| 452 | my $none = $example->none(sub { | ||||||||||||||||||||
| 453 | # ... | ||||||||||||||||||||
| 454 | }); | ||||||||||||||||||||
| 455 | |||||||||||||||||||||
| 456 | =back | ||||||||||||||||||||
| 457 | |||||||||||||||||||||
| 458 | =cut | ||||||||||||||||||||
| 459 | |||||||||||||||||||||
| 460 | =head2 one | ||||||||||||||||||||
| 461 | |||||||||||||||||||||
| 462 | one(coderef $code) (boolean) | ||||||||||||||||||||
| 463 | |||||||||||||||||||||
| 464 | The one method should return true if only one of the items in the data | ||||||||||||||||||||
| 465 | structure meet the criteria set by the operand and rvalue. | ||||||||||||||||||||
| 466 | |||||||||||||||||||||
| 467 | |||||||||||||||||||||
| 468 | |||||||||||||||||||||
| 469 | |||||||||||||||||||||
| 470 | I<Since C<0.01>> | ||||||||||||||||||||
| 471 | |||||||||||||||||||||
| 472 | =over 4 | ||||||||||||||||||||
| 473 | |||||||||||||||||||||
| 474 | =item one example 1 | ||||||||||||||||||||
| 475 | |||||||||||||||||||||
| 476 | # given: synopsis; | ||||||||||||||||||||
| 477 | |||||||||||||||||||||
| 478 | my $one = $example->one(sub { | ||||||||||||||||||||
| 479 | # ... | ||||||||||||||||||||
| 480 | }); | ||||||||||||||||||||
| 481 | |||||||||||||||||||||
| 482 | =back | ||||||||||||||||||||
| 483 | |||||||||||||||||||||
| 484 | =cut | ||||||||||||||||||||
| 485 | |||||||||||||||||||||
| 486 | =head2 pairs | ||||||||||||||||||||
| 487 | |||||||||||||||||||||
| 488 | pairs(coderef $code) (tuple[arrayref, arrayref]) | ||||||||||||||||||||
| 489 | |||||||||||||||||||||
| 490 | The pairs method should return an array reference of tuples where each tuple is | ||||||||||||||||||||
| 491 | an array reference having two items corresponding to the key and value for each | ||||||||||||||||||||
| 492 | item in the data structure. | ||||||||||||||||||||
| 493 | |||||||||||||||||||||
| 494 | |||||||||||||||||||||
| 495 | |||||||||||||||||||||
| 496 | |||||||||||||||||||||
| 497 | I<Since C<0.01>> | ||||||||||||||||||||
| 498 | |||||||||||||||||||||
| 499 | =over 4 | ||||||||||||||||||||
| 500 | |||||||||||||||||||||
| 501 | =item pairs example 1 | ||||||||||||||||||||
| 502 | |||||||||||||||||||||
| 503 | # given: synopsis; | ||||||||||||||||||||
| 504 | |||||||||||||||||||||
| 505 | my $pairs = $example->pairs(sub { | ||||||||||||||||||||
| 506 | # ... | ||||||||||||||||||||
| 507 | }); | ||||||||||||||||||||
| 508 | |||||||||||||||||||||
| 509 | =back | ||||||||||||||||||||
| 510 | |||||||||||||||||||||
| 511 | =cut | ||||||||||||||||||||
| 512 | |||||||||||||||||||||
| 513 | =head2 random | ||||||||||||||||||||
| 514 | |||||||||||||||||||||
| 515 | random() (any) | ||||||||||||||||||||
| 516 | |||||||||||||||||||||
| 517 | The random method should return a random item from the data structure. | ||||||||||||||||||||
| 518 | |||||||||||||||||||||
| 519 | |||||||||||||||||||||
| 520 | |||||||||||||||||||||
| 521 | |||||||||||||||||||||
| 522 | I<Since C<0.01>> | ||||||||||||||||||||
| 523 | |||||||||||||||||||||
| 524 | =over 4 | ||||||||||||||||||||
| 525 | |||||||||||||||||||||
| 526 | =item random example 1 | ||||||||||||||||||||
| 527 | |||||||||||||||||||||
| 528 | # given: synopsis; | ||||||||||||||||||||
| 529 | |||||||||||||||||||||
| 530 | my $random = $example->random; | ||||||||||||||||||||
| 531 | |||||||||||||||||||||
| 532 | =back | ||||||||||||||||||||
| 533 | |||||||||||||||||||||
| 534 | =cut | ||||||||||||||||||||
| 535 | |||||||||||||||||||||
| 536 | =head2 reverse | ||||||||||||||||||||
| 537 | |||||||||||||||||||||
| 538 | reverse() (arrayref) | ||||||||||||||||||||
| 539 | |||||||||||||||||||||
| 540 | The reverse method should returns an array reference containing the items in | ||||||||||||||||||||
| 541 | the data structure in reverse order if the items in the data structure are | ||||||||||||||||||||
| 542 | ordered. | ||||||||||||||||||||
| 543 | |||||||||||||||||||||
| 544 | |||||||||||||||||||||
| 545 | |||||||||||||||||||||
| 546 | |||||||||||||||||||||
| 547 | I<Since C<0.01>> | ||||||||||||||||||||
| 548 | |||||||||||||||||||||
| 549 | =over 4 | ||||||||||||||||||||
| 550 | |||||||||||||||||||||
| 551 | =item reverse example 1 | ||||||||||||||||||||
| 552 | |||||||||||||||||||||
| 553 | # given: synopsis; | ||||||||||||||||||||
| 554 | |||||||||||||||||||||
| 555 | my $reverse = $example->reverse; | ||||||||||||||||||||
| 556 | |||||||||||||||||||||
| 557 | =back | ||||||||||||||||||||
| 558 | |||||||||||||||||||||
| 559 | =cut | ||||||||||||||||||||
| 560 | |||||||||||||||||||||
| 561 | =head2 slice | ||||||||||||||||||||
| 562 | |||||||||||||||||||||
| 563 | slice(string @keys) (arrayref) | ||||||||||||||||||||
| 564 | |||||||||||||||||||||
| 565 | The slice method should return a new data structure containing the elements in | ||||||||||||||||||||
| 566 | the invocant at the key(s) specified in the arguments. | ||||||||||||||||||||
| 567 | |||||||||||||||||||||
| 568 | |||||||||||||||||||||
| 569 | |||||||||||||||||||||
| 570 | |||||||||||||||||||||
| 571 | I<Since C<0.01>> | ||||||||||||||||||||
| 572 | |||||||||||||||||||||
| 573 | =over 4 | ||||||||||||||||||||
| 574 | |||||||||||||||||||||
| 575 | =item slice example 1 | ||||||||||||||||||||
| 576 | |||||||||||||||||||||
| 577 | # given: synopsis; | ||||||||||||||||||||
| 578 | |||||||||||||||||||||
| 579 | my $slice = $example->slice(...); | ||||||||||||||||||||
| 580 | |||||||||||||||||||||
| 581 | =back | ||||||||||||||||||||
| 582 | |||||||||||||||||||||
| 583 | =cut | ||||||||||||||||||||
| 584 | |||||||||||||||||||||
| 585 | =head1 AUTHORS | ||||||||||||||||||||
| 586 | |||||||||||||||||||||
| 587 | Awncorp, C<awncorp@cpan.org> | ||||||||||||||||||||
| 588 | |||||||||||||||||||||
| 589 | =cut | ||||||||||||||||||||
| 590 | |||||||||||||||||||||
| 591 | =head1 LICENSE | ||||||||||||||||||||
| 592 | |||||||||||||||||||||
| 593 | Copyright (C) 2022, Awncorp, C<awncorp@cpan.org>. | ||||||||||||||||||||
| 594 | |||||||||||||||||||||
| 595 | This program is free software, you can redistribute it and/or modify it under | ||||||||||||||||||||
| 596 | the terms of the Apache license version 2.0. | ||||||||||||||||||||
| 597 | |||||||||||||||||||||
| 598 | =cut | ||||||||||||||||||||