blib/lib/Venus/Name.pm

filter: Statementstmt 100% 75 / 75 Branchbran 83.3% 10 / 12 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 22 / 22 Podpod 92.8% 13 / 14 totaltotal 96.0% 121 / 126 CC 8 SCAR 5.3
CC
8
Cov
97%
package
4.0
format
2.0
file
2.0
CRAP 1.7
« blib/lib/Venus/Task/Venus/Run.pm ↑ Summary blib/lib/Venus/Dump.pm »
1 package Venus::Name;
2  
3 30 ▶use 5.018;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 30 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 30 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # IMPORTS
9  
10 30 ▶use Venus::Class 'base', 'with';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # INHERITS
13  
14 30 base 'Venus::Kind::Utility';
15  
16 # INTEGRATES
17  
18 30 with 'Venus::Role::Valuable';
19 30 with 'Venus::Role::Buildable';
20 30 with 'Venus::Role::Accessible';
21 30 with 'Venus::Role::Explainable';
22  
23 # OVERLOADS
24  
25 30 ▶use overload (
Subroutine BEGIN: called CC=1 SCAR=0.0
26 '""' => 'explain',
27 3 ▶ 'eq' => sub{$_[0]->value eq "$_[1]"},
Subroutine __ANON__: called CC=1 SCAR=0.0
28 2 ▶ 'ne' => sub{$_[0]->value ne "$_[1]"},
Subroutine __ANON__: called CC=1 SCAR=0.0
29 1 ▶ 'qr' => sub{qr/@{[quotemeta($_[0]->value)]}/},
Subroutine __ANON__: called CC=1 SCAR=0.0
30 30 '~~' => 'explain',
31 fallback => 1,
32 30 );
33  
34 30 my $sep = qr/'|__|::|\\|\//;
35  
36 # BUILDERS
37  
38 739 ▶sub build_arg {
Subroutine build_arg: called CC=1 SCAR=0.0
Pod undocumented
39 739 my ($self, $data) = @_;
40  
41 return {
42 739 value => $data,
43 };
44 }
45  
46 # METHODS
47  
48 3 ▶sub default {
Subroutine default: called CC=1 SCAR=0.0
Pod documented
49 3 return 'Venus';
50 }
51  
52 1 ▶sub dist {
Subroutine dist: called CC=1 SCAR=0.0
Pod documented
53 1 my ($self) = @_;
54  
55 1 return $self->label =~ s/_/-/gr;
56 }
57  
58 13 ▶sub explain {
Subroutine explain: called CC=1 SCAR=0.0
Pod documented
59 13 my ($self) = @_;
60  
61 13 return $self->get;
62 }
63  
64 2 ▶sub file {
Subroutine file: called CC=2 SCAR=7.0
Pod documented
65 2 my ($self) = @_;
66  
67 2 ▶ return $self->get if $self->lookslike_a_file;
Branch: 1 branch
BranchTrueFalseTotal
if $self->lookslike_a_file 0 2 2
68  
69 2 my $string = $self->package;
70  
71 return join '__', map {
72 2 join '_', map {lc} map {split /_/} grep {length}
73 split /([A-Z]{1}[^A-Z]*)/
74 } split /$sep/, $string;
75 }
76  
77 607 ▶sub format {
Subroutine format: called CC=2 SCAR=7.0
Pod documented
78 607 my ($self, $method, $format) = @_;
79  
80 607 local $_ = $self;
81  
82 607 my $string = $self->$method;
83  
84 607 ▶ return sprintf($format || '%s', $string);
Condition50%1/2
$format || '%s'
l!l
6070
MC/DC0%0/1
$format || '%s'
$format
Truth table50%1/2
A
A= $format
Aresult
11
00
85 }
86  
87 179 ▶sub label {
Subroutine label: called CC=2 SCAR=6.9
Pod documented
88 179 my ($self) = @_;
89  
90 179 ▶ return $self->get if $self->lookslike_a_label;
Branch: 1 branch
BranchTrueFalseTotal
if $self->lookslike_a_label 140 39 179
91  
92 39 return join '_', split /$sep/, $self->package;
93 }
94  
95 3 ▶sub lookslike_a_file {
Subroutine lookslike_a_file: called CC=1 SCAR=0.0
Pod documented
96 3 my ($self) = @_;
97  
98 3 my $string = $self->get;
99  
100 3 return $string =~ /^[a-z](?:\w*[a-z])?$/;
101 }
102  
103 180 ▶sub lookslike_a_label {
Subroutine lookslike_a_label: called CC=1 SCAR=0.0
Pod documented
104 180 my ($self) = @_;
105  
106 180 my $string = $self->get;
107  
108 180 return $string =~ /^[A-Z](?:\w*[a-zA-Z0-9])?$/;
109 }
110  
111 2064 ▶sub lookslike_a_package {
Subroutine lookslike_a_package: called CC=1 SCAR=0.0
Pod documented
112 2064 my ($self) = @_;
113  
114 2064 my $string = $self->get;
115  
116 2064 return $string =~ /^[A-Z](?:(?:\w|::)*[a-zA-Z0-9])?$/;
117 }
118  
119 658 ▶sub lookslike_a_path {
Subroutine lookslike_a_path: called CC=1 SCAR=0.0
Pod documented
120 658 my ($self) = @_;
121  
122 658 my $string = $self->get;
123  
124 658 return $string =~ /^[A-Z](?:(?:\w|\\|\/|[\:\.]{1}[a-zA-Z0-9])*[a-zA-Z0-9])?$/;
125 }
126  
127 835 ▶sub lookslike_a_pragma {
Subroutine lookslike_a_pragma: called CC=1 SCAR=0.0
Pod documented
128 835 my ($self) = @_;
129  
130 835 my $string = $self->get;
131  
132 835 return $string =~ /^\[\w+\]$/;
133 }
134  
135 2057 ▶sub package {
Subroutine package: called CC=4 SCAR=13.9
Pod documented
136 2057 my ($self) = @_;
137  
138 2057 ▶ return $self->get if $self->lookslike_a_package;
Branch: 1 branch
BranchTrueFalseTotal
if $self->lookslike_a_package 1828 229 2057
139  
140 229 ▶ return substr($self->get, 1, -1) if $self->lookslike_a_pragma;
Branch: 1 branch
BranchTrueFalseTotal
if $self->lookslike_a_pragma 0 229 229
141  
142 229 my $string = $self->get;
143  
144 229 ▶ if ($string !~ $sep) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $string =~ /$sep/u) { } 40 189 229
145 40 return join '', map {ucfirst} split /[^a-zA-Z0-9]/, $string;
146 } else {
147 return join '::', map {
148 189 join '', map {ucfirst} split /[^a-zA-Z0-9]/
149 } split /$sep/, $string;
150 }
151 }
152  
153 657 ▶sub path {
Subroutine path: called CC=2 SCAR=6.9
Pod documented
154 657 my ($self) = @_;
155  
156 657 ▶ return $self->get if $self->lookslike_a_path;
Branch: 1 branch
BranchTrueFalseTotal
if $self->lookslike_a_path 327 330 657
157  
158 330 return join '/', split /$sep/, $self->package;
159 }
160  
161 30 1;
162  
163  
164  
165 =head1 NAME
166  
167 Venus::Name - Name Class
168  
169 =cut
170  
171 =head1 ABSTRACT
172  
173 Name Class for Perl 5
174  
175 =cut
176  
177 =head1 SYNOPSIS
178  
179 package main;
180  
181 use Venus::Name;
182  
183 my $name = Venus::Name->new('Foo/Bar');
184  
185 # $name->package;
186  
187 =cut
188  
189 =head1 DESCRIPTION
190  
191 This package provides methods for parsing and formatting package namespace
192 strings.
193  
194 =cut
195  
196 =head1 INHERITS
197  
198 This package inherits behaviors from:
199  
200 L<Venus::Kind::Utility>
201  
202 =cut
203  
204 =head1 INTEGRATES
205  
206 This package integrates behaviors from:
207  
208 L<Venus::Role::Accessible>
209  
210 L<Venus::Role::Buildable>
211  
212 L<Venus::Role::Explainable>
213  
214 L<Venus::Role::Valuable>
215  
216 =cut
217  
218 =head1 METHODS
219  
220 This package provides the following methods:
221  
222 =cut
223  
224 =head2 default
225  
226 default() (string)
227  
228 The default method returns the default value, i.e. C<'Venus'>.
229  
230 I<Since C<0.01>>
231  
232 =over 4
233  
234 =item default example 1
235  
236 # given: synopsis;
237  
238 my $default = $name->default;
239  
240 # "Venus"
241  
242 =back
243  
244 =cut
245  
246 =head2 dist
247  
248 dist() (string)
249  
250 The dist method returns a package distribution representation of the name.
251  
252 I<Since C<0.01>>
253  
254 =over 4
255  
256 =item dist example 1
257  
258 # given: synopsis;
259  
260 my $dist = $name->dist;
261  
262 # "Foo-Bar"
263  
264 =back
265  
266 =cut
267  
268 =head2 explain
269  
270 explain() (string)
271  
272 The explain method returns the package name and is used in stringification
273 operations.
274  
275 I<Since C<0.01>>
276  
277 =over 4
278  
279 =item explain example 1
280  
281 # given: synopsis;
282  
283 my $explain = $name->explain;
284  
285 # "Foo/Bar"
286  
287 =back
288  
289 =cut
290  
291 =head2 file
292  
293 file() (string)
294  
295 The file method returns a file representation of the name.
296  
297 I<Since C<0.01>>
298  
299 =over 4
300  
301 =item file example 1
302  
303 # given: synopsis;
304  
305 my $file = $name->file;
306  
307 # "foo__bar"
308  
309 =back
310  
311 =cut
312  
313 =head2 format
314  
315 format(string $method, string $format) (string)
316  
317 The format method calls the specified method passing the result to the core
318 L</sprintf> function with itself as an argument. This method supports
319 dispatching, i.e. providing a method name and arguments whose return value will
320 be acted on by this method.
321  
322 I<Since C<0.01>>
323  
324 =over 4
325  
326 =item format example 1
327  
328 # given: synopsis;
329  
330 my $format = $name->format('file', '%s.t');
331  
332 # "foo__bar.t"
333  
334 =back
335  
336 =cut
337  
338 =head2 label
339  
340 label() (string)
341  
342 The label method returns a label (or constant) representation of the name.
343  
344 I<Since C<0.01>>
345  
346 =over 4
347  
348 =item label example 1
349  
350 # given: synopsis;
351  
352 my $label = $name->label;
353  
354 # "Foo_Bar"
355  
356 =back
357  
358 =cut
359  
360 =head2 lookslike_a_file
361  
362 lookslike_a_file() (string)
363  
364 The lookslike_a_file method returns truthy if its state resembles a filename.
365  
366 I<Since C<0.01>>
367  
368 =over 4
369  
370 =item lookslike_a_file example 1
371  
372 # given: synopsis;
373  
374 my $lookslike_a_file = $name->lookslike_a_file;
375  
376 # ""
377  
378 =back
379  
380 =cut
381  
382 =head2 lookslike_a_label
383  
384 lookslike_a_label() (string)
385  
386 The lookslike_a_label method returns truthy if its state resembles a label (or
387 constant).
388  
389 I<Since C<0.01>>
390  
391 =over 4
392  
393 =item lookslike_a_label example 1
394  
395 # given: synopsis;
396  
397 my $lookslike_a_label = $name->lookslike_a_label;
398  
399 # ""
400  
401 =back
402  
403 =cut
404  
405 =head2 lookslike_a_package
406  
407 lookslike_a_package() (string)
408  
409 The lookslike_a_package method returns truthy if its state resembles a package
410 name.
411  
412 I<Since C<0.01>>
413  
414 =over 4
415  
416 =item lookslike_a_package example 1
417  
418 # given: synopsis;
419  
420 my $lookslike_a_package = $name->lookslike_a_package;
421  
422 # ""
423  
424 =back
425  
426 =cut
427  
428 =head2 lookslike_a_path
429  
430 lookslike_a_path() (string)
431  
432 The lookslike_a_path method returns truthy if its state resembles a file path.
433  
434 I<Since C<0.01>>
435  
436 =over 4
437  
438 =item lookslike_a_path example 1
439  
440 # given: synopsis;
441  
442 my $lookslike_a_path = $name->lookslike_a_path;
443  
444 # 1
445  
446 =back
447  
448 =cut
449  
450 =head2 lookslike_a_pragma
451  
452 lookslike_a_pragma() (string)
453  
454 The lookslike_a_pragma method returns truthy if its state resembles a pragma.
455  
456 I<Since C<0.01>>
457  
458 =over 4
459  
460 =item lookslike_a_pragma example 1
461  
462 # given: synopsis;
463  
464 my $lookslike_a_pragma = $name->lookslike_a_pragma;
465  
466 # ""
467  
468 =back
469  
470 =cut
471  
472 =head2 new
473  
474 new(any @args) (Venus::Name)
475  
476 The new method constructs an instance of the package.
477  
478 I<Since C<4.15>>
479  
480 =over 4
481  
482 =item new example 1
483  
484 package main;
485  
486 use Venus::Name;
487  
488 my $new = Venus::Name->new;
489  
490 # bless(..., "Venus::Name")
491  
492 =back
493  
494 =over 4
495  
496 =item new example 2
497  
498 package main;
499  
500 use Venus::Name;
501  
502 my $new = Venus::Name->new('Foo/Bar');
503  
504 # bless(..., "Venus::Name")
505  
506 =back
507  
508 =over 4
509  
510 =item new example 3
511  
512 package main;
513  
514 use Venus::Name;
515  
516 my $new = Venus::Name->new(value => 'Foo/Bar');
517  
518 # bless(..., "Venus::Name")
519  
520 =back
521  
522 =cut
523  
524 =head2 package
525  
526 package() (string)
527  
528 The package method returns a package name representation of the name given.
529  
530 I<Since C<0.01>>
531  
532 =over 4
533  
534 =item package example 1
535  
536 # given: synopsis;
537  
538 my $package = $name->package;
539  
540 # "Foo::Bar"
541  
542 =back
543  
544 =cut
545  
546 =head2 path
547  
548 path() (string)
549  
550 The path method returns a path representation of the name.
551  
552 I<Since C<0.01>>
553  
554 =over 4
555  
556 =item path example 1
557  
558 # given: synopsis;
559  
560 my $path = $name->path;
561  
562 # "Foo/Bar"
563  
564 =back
565  
566 =cut
567  
568 =head1 OPERATORS
569  
570 This package overloads the following operators:
571  
572 =cut
573  
574 =over 4
575  
576 =item operation: C<("")>
577  
578 This package overloads the C<""> operator.
579  
580 B<example 1>
581  
582 # given: synopsis;
583  
584 my $result = "$name";
585  
586 # "Foo/Bar"
587  
588 B<example 2>
589  
590 # given: synopsis;
591  
592 my $result = "$name, $name";
593  
594 # "Foo/Bar, Foo/Bar"
595  
596 =back
597  
598 =over 4
599  
600 =item operation: C<(.)>
601  
602 This package overloads the C<.> operator.
603  
604 B<example 1>
605  
606 # given: synopsis;
607  
608 my $package = $name . 'Baz';
609  
610 # "Foo::BarBaz"
611  
612 =back
613  
614 =over 4
615  
616 =item operation: C<(eq)>
617  
618 This package overloads the C<eq> operator.
619  
620 B<example 1>
621  
622 # given: synopsis;
623  
624 $name eq 'Foo/Bar';
625  
626 # 1
627  
628 B<example 2>
629  
630 package main;
631  
632 use Venus::Name;
633  
634 my $name1 = Venus::Name->new('Foo\Bar');
635 my $name2 = Venus::Name->new('Foo\Bar');
636  
637 $name1 eq $name2;
638  
639 # 1
640  
641 =back
642  
643 =over 4
644  
645 =item operation: C<(ne)>
646  
647 This package overloads the C<ne> operator.
648  
649 B<example 1>
650  
651 # given: synopsis;
652  
653 $name ne 'Foo\Bar';
654  
655 # 1
656  
657 B<example 2>
658  
659 package main;
660  
661 use Venus::Name;
662  
663 my $name1 = Venus::Name->new('FooBar');
664 my $name2 = Venus::Name->new('Foo_Bar');
665  
666 $name1 ne $name2;
667  
668 # 1
669  
670 =back
671  
672 =over 4
673  
674 =item operation: C<(qr)>
675  
676 This package overloads the C<qr> operator.
677  
678 B<example 1>
679  
680 # given: synopsis;
681  
682 "Foo/Bar" =~ qr/$name/;
683  
684 # 1
685  
686 =back
687  
688 =over 4
689  
690 =item operation: C<(~~)>
691  
692 This package overloads the C<~~> operator.
693  
694 B<example 1>
695  
696 # given: synopsis;
697  
698 my $result = $name ~~ 'Foo/Bar';
699  
700 # 1
701  
702 =back
703  
704 =head1 AUTHORS
705  
706 Awncorp, C<awncorp@cpan.org>
707  
708 =cut
709  
710 =head1 LICENSE
711  
712 Copyright (C) 2022, Awncorp, C<awncorp@cpan.org>.
713  
714 This program is free software, you can redistribute it and/or modify it under
715 the terms of the Apache license version 2.0.
716  
717 =cut
« blib/lib/Venus/Task/Venus/Run.pm ↑ Summary blib/lib/Venus/Dump.pm »