Faker/Plugin.pm

filter: Statementstmt 100% 54 / 54 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 15 / 15 Podpod 45.4% 5 / 11 totaltotal 92.8% 78 / 84 CC 5 SCAR 4.2
CC
5
Cov
100%
process_markers
3.0
process_format
2.0
transliterate
2.0
CRAP 1.5
« Faker.pm ↑ Summary Faker/Plugin/EsEs.pm »
1 package Faker::Plugin;
2  
3 150 ▶use 5.018;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 150 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 150 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 150 ▶use Venus::Class 'attr', 'with';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 150 with 'Venus::Role::Buildable';
11 150 with 'Venus::Role::Optional';
12  
13 # VERSION
14  
15 150 our $VERSION = '1.19';
16  
17 # ATTRIBUTES
18  
19 150 attr 'faker';
20  
21 # DEFAULTS
22  
23 9768 ▶sub coerce_faker {
Subroutine coerce_faker: called CC=1 SCAR=0.0
Pod undocumented
24 9768 return 'Faker';
25 }
26  
27 455 ▶sub default_faker {
Subroutine default_faker: called CC=1 SCAR=0.0
Pod undocumented
28 455 return {};
29 }
30  
31 # METHODS
32  
33 1 ▶sub execute {
Subroutine execute: called CC=1 SCAR=0.0
Pod documented
34 1 my ($self, $data) = @_;
35  
36 1 return '';
37 }
38  
39 5 ▶sub process {
Subroutine process: called CC=1 SCAR=0.0
Pod documented
40 5 my ($self, $data, @types) = @_;
41  
42 5 return $self->process_format($self->process_markers($data, @types));
43 }
44  
45 295 ▶sub process_format {
Subroutine process_format: called CC=2 SCAR=6.9
Pod documented
46 295 my ($self, $data) = @_;
47  
48 295 ▶ $data = join ' ', @$data if ref $data eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $data eq "ARRAY" 42 253 295
49  
50 295 $data =~ s/\{\{\s?([#\.\w]+)\s?\}\}/$self->resolve($1)/eg;
51  
52 295 return $data;
53 }
54  
55 197 ▶sub process_markers {
Subroutine process_markers: called CC=3 SCAR=11.0
Pod documented
56 197 my ($self, $data, @types) = @_;
57  
58 197 ▶ my @methods = map "process_markers_for_${_}", (
Branch: 1 branch
BranchTrueFalseTotal
@types ? : 168 29 197
59 @types ? @types : qw(letters newlines numbers)
60 );
61  
62 197 for my $method (@methods) {
63 270 $data = $self->$method($data);
64 }
65  
66 197 return $data;
67 }
68  
69 44 ▶sub process_markers_for_letters {
Subroutine process_markers_for_letters: called CC=1 SCAR=0.0
Pod undocumented
70 44 my ($self, $data) = @_;
71  
72 44 my $random = $self->faker->random;
73  
74 44 $data =~ s/\?/$random->letter/eg;
75  
76 44 return $data;
77 }
78  
79 51 ▶sub process_markers_for_newlines {
Subroutine process_markers_for_newlines: called CC=1 SCAR=0.0
Pod undocumented
80 51 my ($self, $data) = @_;
81  
82 51 $data =~ s/\\n/\n/g;
83  
84 51 return $data;
85 }
86  
87 175 ▶sub process_markers_for_numbers {
Subroutine process_markers_for_numbers: called CC=1 SCAR=0.0
Pod undocumented
88 175 my ($self, $data) = @_;
89  
90 175 my $random = $self->faker->random;
91  
92 175 $data =~ s/\#/$random->digit/eg;
93 175 $data =~ s/\%/$random->nonzero('digit')/eg;
94  
95 175 return $data;
96 }
97  
98 640 ▶sub resolve {
Subroutine resolve: called CC=1 SCAR=0.0
Pod documented
99 640 my ($self, $method) = @_;
100  
101 640 return $self->faker->$method;
102 }
103  
104 13 ▶sub transliterate {
Subroutine transliterate: called CC=2 SCAR=6.9
Pod undocumented
105 13 my ($self, $data) = @_;
106  
107 13 state $table = {
108 "'" => '',
109 '/' => '',
110 'À' => 'A',
111 'Á' => 'A',
112 'Â' => 'A',
113 'Ã' => 'A',
114 'Ä' => 'A',
115 'Å' => 'A',
116 'Æ' => 'A',
117 'Ç' => 'C',
118 'È' => 'E',
119 'É' => 'E',
120 'Ê' => 'E',
121 'Ë' => 'E',
122 'Ì' => 'I',
123 'Í' => 'I',
124 'Î' => 'I',
125 'Ï' => 'I',
126 'Ð' => 'D',
127 'Ñ' => 'N',
128 'Ò' => 'O',
129 'Ó' => 'O',
130 'Ô' => 'O',
131 'Õ' => 'O',
132 'Ö' => 'O',
133 'Ø' => 'O',
134 'Ù' => 'U',
135 'Ú' => 'U',
136 'Û' => 'U',
137 'Ü' => 'U',
138 'Ý' => 'Y',
139 'Þ' => 'T',
140 'ß' => 's',
141 'à' => 'a',
142 'á' => 'a',
143 'â' => 'a',
144 'ã' => 'a',
145 'ä' => 'a',
146 'å' => 'a',
147 'æ' => 'a',
148 'ç' => 'c',
149 'è' => 'e',
150 'é' => 'e',
151 'ê' => 'e',
152 'ë' => 'e',
153 'ì' => 'i',
154 'í' => 'i',
155 'î' => 'i',
156 'ï' => 'i',
157 'ð' => 'd',
158 'ñ' => 'n',
159 'ò' => 'o',
160 'ó' => 'o',
161 'ô' => 'o',
162 'õ' => 'o',
163 'ö' => 'o',
164 'ø' => 'o',
165 'ù' => 'u',
166 'ú' => 'u',
167 'û' => 'u',
168 'ü' => 'u',
169 'ý' => 'y',
170 'þ' => 't',
171 'ÿ' => 'y',
172 'Ā' => 'A',
173 'ā' => 'a',
174 'Ă' => 'A',
175 'ă' => 'a',
176 'Ą' => 'A',
177 'ą' => 'a',
178 'Ć' => 'C',
179 'ć' => 'c',
180 'Ĉ' => 'C',
181 'ĉ' => 'c',
182 'Ċ' => 'C',
183 'ċ' => 'c',
184 'Č' => 'C',
185 'č' => 'c',
186 'Ď' => 'D',
187 'ď' => 'd',
188 'Đ' => 'D',
189 'đ' => 'd',
190 'Ē' => 'E',
191 'ē' => 'e',
192 'Ĕ' => 'E',
193 'ĕ' => 'e',
194 'Ė' => 'E',
195 'ė' => 'e',
196 'Ę' => 'E',
197 'ę' => 'e',
198 'Ě' => 'E',
199 'ě' => 'e',
200 'Ĝ' => 'G',
201 'ĝ' => 'g',
202 'Ğ' => 'G',
203 'ğ' => 'g',
204 'Ġ' => 'G',
205 'ġ' => 'g',
206 'Ģ' => 'G',
207 'ģ' => 'g',
208 'Ĥ' => 'H',
209 'ĥ' => 'h',
210 'Ħ' => 'H',
211 'ħ' => 'h',
212 'Ĩ' => 'I',
213 'ĩ' => 'i',
214 'Ī' => 'I',
215 'ī' => 'i',
216 'Ĭ' => 'I',
217 'ĭ' => 'i',
218 'Į' => 'I',
219 'į' => 'i',
220 'İ' => 'I',
221 'ı' => 'i',
222 'IJ' => 'I',
223 'ij' => 'i',
224 'Ĵ' => 'J',
225 'ĵ' => 'j',
226 'Ķ' => 'K',
227 'ķ' => 'k',
228 'ĸ' => 'k',
229 'Ĺ' => 'K',
230 'ĺ' => 'l',
231 'Ļ' => 'K',
232 'ļ' => 'l',
233 'Ľ' => 'K',
234 'ľ' => 'l',
235 'Ŀ' => 'K',
236 'ŀ' => 'l',
237 'Ł' => 'L',
238 'ł' => 'l',
239 'Ń' => 'N',
240 'ń' => 'n',
241 'Ņ' => 'N',
242 'ņ' => 'n',
243 'Ň' => 'N',
244 'ň' => 'n',
245 'ʼn' => 'n',
246 'Ŋ' => 'N',
247 'ŋ' => 'n',
248 'Ō' => 'O',
249 'ō' => 'o',
250 'Ŏ' => 'O',
251 'ŏ' => 'o',
252 'Ő' => 'O',
253 'ő' => 'o',
254 'Œ' => 'O',
255 'œ' => 'o',
256 'Ŕ' => 'R',
257 'ŕ' => 'r',
258 'Ŗ' => 'R',
259 'ŗ' => 'r',
260 'Ř' => 'R',
261 'ř' => 'r',
262 'Ś' => 'S',
263 'ś' => 's',
264 'Ŝ' => 'S',
265 'Ş' => 'S',
266 'ş' => 's',
267 'Š' => 'S',
268 'š' => 's',
269 'Ţ' => 'T',
270 'ţ' => 't',
271 'Ť' => 'T',
272 'ť' => 't',
273 'Ŧ' => 'T',
274 'Ũ' => 'U',
275 'ũ' => 'u',
276 'Ū' => 'U',
277 'ū' => 'u',
278 'Ŭ' => 'U',
279 'ŭ' => 'u',
280 'Ů' => 'U',
281 'ů' => 'u',
282 'Ű' => 'U',
283 'ű' => 'u',
284 'Ų' => 'U',
285 'ų' => 'u',
286 'Ŵ' => 'W',
287 'ŵ' => 'w',
288 'Ŷ' => 'Y',
289 'ŷ' => 'y',
290 'Ÿ' => 'Y',
291 'Ź' => 'Z',
292 'ź' => 'z',
293 'Ż' => 'Z',
294 'ż' => 'z',
295 'Ž' => 'Z',
296 'ž' => 'z',
297 'ſ' => 's',
298 'ƒ' => 'f',
299 'ơ' => 'o',
300 'ư' => 'u',
301 'Ș' => 'S',
302 'ș' => 's',
303 'Ț' => 'T',
304 'ț' => 't',
305 'ʼ' => "'",
306 '̧' => '',
307 'Ά' => 'A',
308 'Έ' => 'E',
309 'Ή' => 'I',
310 'Ί' => 'I',
311 'Ό' => 'O',
312 'Ύ' => 'Y',
313 'Ώ' => 'O',
314 'ΐ' => 'i',
315 'Α' => 'A',
316 'Β' => 'B',
317 'Γ' => 'G',
318 'Δ' => 'D',
319 'Ε' => 'E',
320 'Ζ' => 'Z',
321 'Η' => 'I',
322 'Θ' => 'T',
323 'Ι' => 'I',
324 'Κ' => 'K',
325 'Λ' => 'L',
326 'Μ' => 'M',
327 'Ν' => 'N',
328 'Ξ' => 'K',
329 'Ο' => 'O',
330 'Π' => 'P',
331 'Ρ' => 'R',
332 'Σ' => 'S',
333 'Τ' => 'T',
334 'Υ' => 'Y',
335 'Φ' => 'F',
336 'Χ' => 'X',
337 'Ψ' => 'P',
338 'Ω' => 'O',
339 'Ϊ' => 'I',
340 'Ϋ' => 'Y',
341 'ά' => 'a',
342 'έ' => 'e',
343 'ή' => 'i',
344 'ί' => 'i',
345 'ΰ' => 'y',
346 'α' => 'a',
347 'β' => 'b',
348 'γ' => 'g',
349 'δ' => 'd',
350 'ε' => 'e',
351 'ζ' => 'z',
352 'η' => 'i',
353 'θ' => 't',
354 'ι' => 'i',
355 'κ' => 'k',
356 'λ' => 'l',
357 'μ' => 'm',
358 'ν' => 'n',
359 'ξ' => 'k',
360 'ο' => 'o',
361 'π' => 'p',
362 'ρ' => 'r',
363 'ς' => 's',
364 'σ' => 's',
365 'τ' => 't',
366 'υ' => 'y',
367 'φ' => 'f',
368 'χ' => 'x',
369 'ψ' => 'p',
370 'ω' => 'o',
371 'ϊ' => 'i',
372 'ϋ' => 'y',
373 'ό' => 'o',
374 'ύ' => 'y',
375 'ώ' => 'o',
376 'Ё' => 'E',
377 'А' => 'A',
378 'Б' => 'B',
379 'В' => 'V',
380 'Г' => 'G',
381 'Д' => 'D',
382 'Е' => 'E',
383 'Ж' => 'Z',
384 'З' => 'Z',
385 'И' => 'I',
386 'Й' => 'I',
387 'К' => 'K',
388 'Л' => 'L',
389 'М' => 'M',
390 'Н' => 'N',
391 'О' => 'O',
392 'П' => 'P',
393 'Р' => 'R',
394 'С' => 'S',
395 'Т' => 'T',
396 'У' => 'U',
397 'Ф' => 'F',
398 'Х' => 'K',
399 'Ц' => 'T',
400 'Ч' => 'C',
401 'Ш' => 'S',
402 'Щ' => 'S',
403 'Ы' => 'Y',
404 'Э' => 'E',
405 'Ю' => 'Y',
406 'Я' => 'Y',
407 'а' => 'A',
408 'б' => 'B',
409 'в' => 'V',
410 'г' => 'G',
411 'д' => 'D',
412 'е' => 'E',
413 'ж' => 'Z',
414 'з' => 'Z',
415 'и' => 'I',
416 'й' => 'I',
417 'к' => 'K',
418 'л' => 'L',
419 'м' => 'M',
420 'н' => 'N',
421 'о' => 'O',
422 'п' => 'P',
423 'р' => 'R',
424 'с' => 'S',
425 'т' => 'T',
426 'у' => 'U',
427 'ф' => 'F',
428 'х' => 'K',
429 'ц' => 'T',
430 'ч' => 'C',
431 'ш' => 'S',
432 'щ' => 'S',
433 'ы' => 'Y',
434 'э' => 'E',
435 'ю' => 'Y',
436 'я' => 'Y',
437 'ё' => 'E',
438 'ա' => 'a',
439 'բ' => 'b',
440 'գ' => 'g',
441 'դ' => 'd',
442 'ե' => 'e',
443 'զ' => 'z',
444 'է' => 'e',
445 'ը' => 'y',
446 'թ' => 't',
447 'ժ' => 'zh',
448 'ի' => 'i',
449 'լ' => 'l',
450 'խ' => 'kh',
451 'ծ' => 'ts',
452 'կ' => 'k',
453 'հ' => 'h',
454 'ձ' => 'dz',
455 'ղ' => 'gh',
456 'ճ' => 'ch',
457 'մ' => 'm',
458 'յ' => 'y',
459 'ն' => 'n',
460 'շ' => 'sh',
461 'ո' => 'o',
462 'ու' => 'u',
463 'չ' => 'ch',
464 'պ' => 'p',
465 'ջ' => 'j',
466 'ռ' => 'r',
467 'ս' => 's',
468 'վ' => 'v',
469 'տ' => 't',
470 'ր' => 'r',
471 'ց' => 'ts',
472 'փ' => 'p',
473 'ք' => 'q',
474 'օ' => 'o',
475 'ֆ' => 'f',
476 'և' => 'ev',
477 'ა' => 'a',
478 'ბ' => 'b',
479 'გ' => 'g',
480 'დ' => 'd',
481 'ე' => 'e',
482 'ვ' => 'v',
483 'ზ' => 'z',
484 'თ' => 't',
485 'ი' => 'i',
486 'კ' => 'k',
487 'ლ' => 'l',
488 'მ' => 'm',
489 'ნ' => 'n',
490 'ო' => 'o',
491 'პ' => 'p',
492 'ჟ' => 'z',
493 'რ' => 'r',
494 'ს' => 's',
495 'ტ' => 't',
496 'უ' => 'u',
497 'ფ' => 'p',
498 'ქ' => 'k',
499 'ღ' => 'g',
500 'ყ' => 'q',
501 'შ' => 's',
502 'ჩ' => 'c',
503 'ც' => 't',
504 'ძ' => 'd',
505 'წ' => 't',
506 'ჭ' => 'c',
507 'ხ' => 'k',
508 'ჯ' => 'j',
509 'ჰ' => 'h',
510 'Ḑ' => 'D',
511 'ḑ' => 'd',
512 'Ḩ' => 'H',
513 'ḩ' => 'h',
514 'ạ' => 'a',
515 'ả' => 'a',
516 'ầ' => 'a',
517 'ậ' => 'a',
518 'ắ' => 'a',
519 'ằ' => 'a',
520 'ẵ' => 'a',
521 'ế' => 'e',
522 'ề' => 'e',
523 'ệ' => 'e',
524 'ỉ' => 'i',
525 'ị' => 'i',
526 'ồ' => 'o',
527 'ộ' => 'o',
528 'ừ' => 'u',
529 'ἀ' => 'a',
530 'ἁ' => 'a',
531 'ἂ' => 'a',
532 'ἃ' => 'a',
533 'ἄ' => 'a',
534 'ἅ' => 'a',
535 'ἆ' => 'a',
536 'ἇ' => 'a',
537 'Ἀ' => 'A',
538 'Ἁ' => 'A',
539 'Ἂ' => 'A',
540 'Ἃ' => 'A',
541 'Ἄ' => 'A',
542 'Ἅ' => 'A',
543 'Ἆ' => 'A',
544 'Ἇ' => 'A',
545 'ἐ' => 'e',
546 'ἑ' => 'e',
547 'ἒ' => 'e',
548 'ἓ' => 'e',
549 'ἔ' => 'e',
550 'ἕ' => 'e',
551 'Ἐ' => 'E',
552 'Ἑ' => 'E',
553 'Ἒ' => 'E',
554 'Ἓ' => 'E',
555 'Ἔ' => 'E',
556 'Ἕ' => 'E',
557 'ἠ' => 'i',
558 'ἡ' => 'i',
559 'ἢ' => 'i',
560 'ἣ' => 'i',
561 'ἤ' => 'i',
562 'ἥ' => 'i',
563 'ἦ' => 'i',
564 'ἧ' => 'i',
565 'Ἠ' => 'I',
566 'Ἡ' => 'I',
567 'Ἢ' => 'I',
568 'Ἣ' => 'I',
569 'Ἤ' => 'I',
570 'Ἥ' => 'I',
571 'Ἦ' => 'I',
572 'Ἧ' => 'I',
573 'ἰ' => 'i',
574 'ἱ' => 'i',
575 'ἲ' => 'i',
576 'ἳ' => 'i',
577 'ἴ' => 'i',
578 'ἵ' => 'i',
579 'ἶ' => 'i',
580 'ἷ' => 'i',
581 'Ἰ' => 'I',
582 'Ἱ' => 'I',
583 'Ἲ' => 'I',
584 'Ἳ' => 'I',
585 'Ἴ' => 'I',
586 'Ἵ' => 'I',
587 'Ἶ' => 'I',
588 'Ἷ' => 'I',
589 'ὀ' => 'o',
590 'ὁ' => 'o',
591 'ὂ' => 'o',
592 'ὃ' => 'o',
593 'ὄ' => 'o',
594 'ὅ' => 'o',
595 'Ὀ' => 'O',
596 'Ὁ' => 'O',
597 'Ὂ' => 'O',
598 'Ὃ' => 'O',
599 'Ὄ' => 'O',
600 'Ὅ' => 'O',
601 'ὐ' => 'y',
602 'ὑ' => 'y',
603 'ὒ' => 'y',
604 'ὓ' => 'y',
605 'ὔ' => 'y',
606 'ὕ' => 'y',
607 'ὖ' => 'y',
608 'ὗ' => 'y',
609 'Ὑ' => 'Y',
610 'Ὓ' => 'Y',
611 'Ὕ' => 'Y',
612 'Ὗ' => 'Y',
613 'ὠ' => 'o',
614 'ὡ' => 'o',
615 'ὢ' => 'o',
616 'ὣ' => 'o',
617 'ὤ' => 'o',
618 'ὥ' => 'o',
619 'ὦ' => 'o',
620 'ὧ' => 'o',
621 'Ὠ' => 'O',
622 'Ὡ' => 'O',
623 'Ὢ' => 'O',
624 'Ὣ' => 'O',
625 'Ὤ' => 'O',
626 'Ὥ' => 'O',
627 'Ὦ' => 'O',
628 'Ὧ' => 'O',
629 'ὰ' => 'a',
630 'ὲ' => 'e',
631 'ὴ' => 'i',
632 'ὶ' => 'i',
633 'ὸ' => 'o',
634 'ὺ' => 'y',
635 'ὼ' => 'o',
636 'ᾀ' => 'a',
637 'ᾁ' => 'a',
638 'ᾂ' => 'a',
639 'ᾃ' => 'a',
640 'ᾄ' => 'a',
641 'ᾅ' => 'a',
642 'ᾆ' => 'a',
643 'ᾇ' => 'a',
644 'ᾈ' => 'A',
645 'ᾉ' => 'A',
646 'ᾊ' => 'A',
647 'ᾋ' => 'A',
648 'ᾌ' => 'A',
649 'ᾍ' => 'A',
650 'ᾎ' => 'A',
651 'ᾏ' => 'A',
652 'ᾐ' => 'i',
653 'ᾑ' => 'i',
654 'ᾒ' => 'i',
655 'ᾓ' => 'i',
656 'ᾔ' => 'i',
657 'ᾕ' => 'i',
658 'ᾖ' => 'i',
659 'ᾗ' => 'i',
660 'ᾘ' => 'I',
661 'ᾙ' => 'I',
662 'ᾚ' => 'I',
663 'ᾛ' => 'I',
664 'ᾜ' => 'I',
665 'ᾝ' => 'I',
666 'ᾞ' => 'I',
667 'ᾟ' => 'I',
668 'ᾠ' => 'o',
669 'ᾡ' => 'o',
670 'ᾢ' => 'o',
671 'ᾣ' => 'o',
672 'ᾤ' => 'o',
673 'ᾥ' => 'o',
674 'ᾦ' => 'o',
675 'ᾧ' => 'o',
676 'ᾨ' => 'O',
677 'ᾩ' => 'O',
678 'ᾪ' => 'O',
679 'ᾫ' => 'O',
680 'ᾬ' => 'O',
681 'ᾭ' => 'O',
682 'ᾮ' => 'O',
683 'ᾯ' => 'O',
684 'ᾰ' => 'a',
685 'ᾱ' => 'a',
686 'ᾲ' => 'a',
687 'ᾳ' => 'a',
688 'ᾴ' => 'a',
689 'ᾶ' => 'a',
690 'ᾷ' => 'a',
691 'Ᾰ' => 'A',
692 'Ᾱ' => 'A',
693 'Ὰ' => 'A',
694 'ᾼ' => 'A',
695 'ῂ' => 'i',
696 'ῃ' => 'i',
697 'ῄ' => 'i',
698 'ῆ' => 'i',
699 'ῇ' => 'i',
700 'Ὲ' => 'E',
701 'Ὴ' => 'I',
702 'ῌ' => 'I',
703 'ῐ' => 'i',
704 'ῑ' => 'i',
705 'ῒ' => 'i',
706 'ῖ' => 'i',
707 'ῗ' => 'i',
708 'Ῐ' => 'I',
709 'Ῑ' => 'I',
710 'Ὶ' => 'I',
711 'ῠ' => 'y',
712 'ῡ' => 'y',
713 'ῢ' => 'y',
714 'ῤ' => 'r',
715 'ῥ' => 'r',
716 'ῦ' => 'y',
717 'ῧ' => 'y',
718 'Ῠ' => 'Y',
719 'Ῡ' => 'Y',
720 'Ὺ' => 'Y',
721 'Ῥ' => 'R',
722 'ῲ' => 'o',
723 'ῳ' => 'o',
724 'ῴ' => 'o',
725 'ῶ' => 'o',
726 'ῷ' => 'o',
727 'Ὸ' => 'O',
728 'Ὼ' => 'O',
729 'ῼ' => 'O',
730 '‘' => "'",
731 '’' => "'",
732 };
733  
734 13 $data =~ s/$_/$$table{$_}/gue for keys %$table;
735  
736 13 return $data;
737 }
738  
739 150 1;
740  
741  
742  
743 =head1 NAME
744  
745 Faker::Plugin - Fake Data Plugin
746  
747 =cut
748  
749 =head1 ABSTRACT
750  
751 Fake Data Plugin Base
752  
753 =cut
754  
755 =head1 VERSION
756  
757 1.19
758  
759 =cut
760  
761 =head1 SYNOPSIS
762  
763 package main;
764  
765 use Faker::Plugin;
766  
767 my $plugin = Faker::Plugin->new;
768  
769 # bless(..., "Faker::Plugin")
770  
771 # my $result = $plugin->execute;
772  
773 # ""
774  
775 =cut
776  
777 =head1 DESCRIPTION
778  
779 This distribution provides a library of fake data generators and a framework
780 for extending the library via plugins.
781  
782 =encoding utf8
783  
784 =cut
785  
786 =head1 ATTRIBUTES
787  
788 This package has the following attributes:
789  
790 =cut
791  
792 =head2 faker
793  
794 faker(Object $data) (Object)
795  
796 The faker attribute holds the L<Faker> object.
797  
798 I<Since C<1.10>>
799  
800 =over 4
801  
802 =item faker example 1
803  
804 # given: synopsis
805  
806 package main;
807  
808 my $faker = $plugin->faker;
809  
810 # bless(..., "Faker")
811  
812 =back
813  
814 =over 4
815  
816 =item faker example 2
817  
818 # given: synopsis
819  
820 package main;
821  
822 my $faker = $plugin->faker({});
823  
824 # bless(..., "Faker")
825  
826 =back
827  
828 =over 4
829  
830 =item faker example 3
831  
832 # given: synopsis
833  
834 package main;
835  
836 use Faker;
837  
838 my $faker = $plugin->faker(Faker->new);
839  
840 # bless(..., "Faker")
841  
842 =back
843  
844 =cut
845  
846 =head1 INTEGRATES
847  
848 This package integrates behaviors from:
849  
850 L<Venus::Role::Buildable>
851  
852 L<Venus::Role::Optional>
853  
854 =cut
855  
856 =head1 METHODS
857  
858 This package provides the following methods:
859  
860 =cut
861  
862 =head2 execute
863  
864 execute(HashRef $data) (Str)
865  
866 The execute method should be overridden by a plugin subclass, and should
867 generate and return a random string.
868  
869 I<Since C<1.10>>
870  
871 =over 4
872  
873 =item execute example 1
874  
875 # given: synopsis
876  
877 package main;
878  
879 my $data = $plugin->execute;
880  
881 # ""
882  
883 =back
884  
885 =cut
886  
887 =head2 new
888  
889 new(HashRef $data) (Plugin)
890  
891 The new method returns a new instance of the class.
892  
893 I<Since C<1.10>>
894  
895 =over 4
896  
897 =item new example 1
898  
899 package main;
900  
901 use Faker::Plugin;
902  
903 my $plugin = Faker::Plugin->new;
904  
905 # bless(... "Faker::Plugin")
906  
907 =back
908  
909 =over 4
910  
911 =item new example 2
912  
913 package main;
914  
915 use Faker::Plugin;
916  
917 my $plugin = Faker::Plugin->new({faker => ['en-us', 'es-es']});
918  
919 # bless(... "Faker::Plugin")
920  
921 =back
922  
923 =over 4
924  
925 =item new example 3
926  
927 package main;
928  
929 use Faker::Plugin;
930  
931 my $plugin = Faker::Plugin->new({faker => Faker->new('ja-jp')});
932  
933 # bless(... "Faker::Plugin")
934  
935 =back
936  
937 =cut
938  
939 =head2 process
940  
941 process(Str $data) (Str)
942  
943 The process method accepts a data template and calls L</process_format> and
944 L</process_markers> with the arguments provided and returns the result.
945  
946 I<Since C<1.10>>
947  
948 =over 4
949  
950 =item process example 1
951  
952 # given: synopsis
953  
954 package main;
955  
956 $plugin->faker->locales(['en-us']);
957  
958 my $process = $plugin->process('@?{{person_last_name}}####');
959  
960 # "\@ZWilkinson4226"
961  
962 =back
963  
964 =cut
965  
966 =head2 process_format
967  
968 process_format(Str $data) (Str)
969  
970 The process_format method accepts a data template replacing any tokens found
971 with the return value from L</resolve>.
972  
973 I<Since C<1.10>>
974  
975 =over 4
976  
977 =item process_format example 1
978  
979 # given: synopsis
980  
981 package main;
982  
983 my $process_format = $plugin->process_format('Version {{software_version}}');
984  
985 # "Version 0.78"
986  
987 =back
988  
989 =cut
990  
991 =head2 process_markers
992  
993 process_markers(Str $data, Str @types) (Str)
994  
995 The process_markers method accepts a string with markers, replaces the markers
996 (i.e. special symbols) and returns the result. This method also, optionally,
997 accepts a list of the types of replacements to be performed. The markers are:
998 C<#> (see L<Venus::Random/digit>), C<%> (see L<Venus::Random/nonzero>), C<?>
999 (see L<Venus::Random/letter>), and C<\n>. The replacement types are:
1000 I<"letters">, I<"numbers">, and I<"newlines">.
1001  
1002 I<Since C<1.10>>
1003  
1004 =over 4
1005  
1006 =item process_markers example 1
1007  
1008 # given: synopsis
1009  
1010 package main;
1011  
1012 my $process_markers = $plugin->process_markers('Version %##');
1013  
1014 # "Version 342"
1015  
1016 =back
1017  
1018 =over 4
1019  
1020 =item process_markers example 2
1021  
1022 # given: synopsis
1023  
1024 package main;
1025  
1026 my $process_markers = $plugin->process_markers('Version %##', 'numbers');
1027  
1028 # "Version 185"
1029  
1030 =back
1031  
1032 =over 4
1033  
1034 =item process_markers example 3
1035  
1036 # given: synopsis
1037  
1038 package main;
1039  
1040 my $process_markers = $plugin->process_markers('Dept. %-??', 'letters', 'numbers');
1041  
1042 # "Dept. 6-EL"
1043  
1044 =back
1045  
1046 =over 4
1047  
1048 =item process_markers example 4
1049  
1050 # given: synopsis
1051  
1052 package main;
1053  
1054 my $process_markers = $plugin->process_markers('root\nsecret', 'newlines');
1055  
1056 # "root\nsecret"
1057  
1058 =back
1059  
1060 =cut
1061  
1062 =head2 resolve
1063  
1064 resolve(Str $name) (Str)
1065  
1066 The resolve method replaces tokens from L</process_format> with the return
1067 value from their corresponding plugins.
1068  
1069 I<Since C<1.10>>
1070  
1071 =over 4
1072  
1073 =item resolve example 1
1074  
1075 # given: synopsis
1076  
1077 package main;
1078  
1079 my $color_hex_code = $plugin->resolve('color_hex_code');
1080  
1081 # "#adfc4b"
1082  
1083 =back
1084  
1085 =over 4
1086  
1087 =item resolve example 2
1088  
1089 # given: synopsis
1090  
1091 package main;
1092  
1093 my $internet_ip_address = $plugin->resolve('internet_ip_address');
1094  
1095 # "edb6:0311:c3e3:fdc1:597d:115c:c179:3998"
1096  
1097 =back
1098  
1099 =over 4
1100  
1101 =item resolve example 3
1102  
1103 # given: synopsis
1104  
1105 package main;
1106  
1107 my $color_name = $plugin->resolve('color_name');
1108  
1109 # "MintCream"
1110  
1111 =back
1112  
1113 =cut
1114  
1115 =head1 FEATURES
1116  
1117 This package provides the following features:
1118  
1119 =cut
1120  
1121 =over 4
1122  
1123 =item subclass-feature
1124  
1125 This package is meant to be subclassed.
1126  
1127 B<example 1>
1128  
1129 package Faker::Plugin::UserId;
1130  
1131 use base 'Faker::Plugin';
1132  
1133 sub execute {
1134 my ($self) = @_;
1135  
1136 return $self->process('####-####');
1137 }
1138  
1139 package main;
1140  
1141 use Faker;
1142  
1143 my $faker = Faker->new;
1144  
1145 # bless(..., "Faker")
1146  
1147 my $result = $faker->user_id;
1148  
1149 # "8359-6325"
1150  
1151 =back
1152  
1153 =head1 AUTHORS
1154  
1155 Awncorp, C<awncorp@cpan.org>
1156  
1157 =cut
1158  
1159 =head1 LICENSE
1160  
1161 Copyright (C) 2000, Al Newkirk.
1162  
1163 This program is free software, you can redistribute it and/or modify it under
1164 the terms of the Apache license version 2.0.
1165  
1166 =cut
« Faker.pm ↑ Summary Faker/Plugin/EsEs.pm »