Zing/Term.pm

filter: Statementstmt 27.8% 57 / 205 Branchbran 0.0% 0 / 68 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 48.0% 12 / 25 Podpod 92.3% 12 / 13 totaltotal 24.9% 81 / 325 CC 39 SCAR 57.9
CC
39
Cov
20%
BUILDARGS
756.0
channel
6.0
data
6.0
CRAP 326.5
↑ Summary Zing/Cli.pm »
1 package Zing::Term;
2  
3 49 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 49 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 49 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 49 ▶use registry 'Zing::Types';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 49 ▶use routines;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 49 ▶use Data::Object::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 49 ▶use Data::Object::ClassHas;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 49 ▶use Zing::Node;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 49 ▶use Zing::Server;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 49 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
18 49 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 49 ▶use overload '""' => 'string';
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 49 our $VERSION = '0.11'; # VERSION
23  
24 # ATTRIBUTES
25  
26 49 has 'facets' => (
27 is => 'ro',
28 isa => 'ArrayRef[Str]',
29 opt => 1,
30 );
31  
32 49 has 'handle' => (
33 is => 'ro',
34 isa => 'Str',
35 req => 1,
36 );
37  
38 49 has 'symbol' => (
39 is => 'ro',
40 isa => 'Str',
41 req => 1,
42 );
43  
44 49 has 'bucket' => (
45 is => 'ro',
46 isa => 'Str',
47 req => 1,
48 );
49  
50 49 has 'system' => (
51 is => 'ro',
52 isa => 'Str',
53 req => 1,
54 );
55  
56 49 has 'target' => (
57 is => 'ro',
58 isa => 'Str',
59 req => 1,
60 );
61  
62 # BUILDERS
63  
64 49 state $symbols = {
65 'Zing::Channel' => 'channel',
66 'Zing::Data' => 'data',
67 'Zing::Domain' => 'domain',
68 'Zing::Kernel' => 'kernel',
69 'Zing::KeyVal' => 'keyval',
70 'Zing::Mailbox' => 'mailbox',
71 'Zing::Process' => 'process',
72 'Zing::PubSub' => 'pubsub',
73 'Zing::Queue' => 'queue',
74 'Zing::Registry' => 'registry',
75 'Zing::Repo' => 'repo',
76 };
77  
78 0 ▶fun BUILDARGS($self, $item, @data) {
Subroutine BUILDARGS: not called CC=27 SCAR=66.3
Pod undocumented
79 0 my $args = {};
80  
81 0 ▶ if (Scalar::Util::blessed($item)) {
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::blessed($item)) { } 0 0 0
elsif (defined $item and not ref $item) { } 0 0 0
82 0 my $local = sprintf 'local(%s)', Zing::Server->new->name;
83  
84 0 @data = map {s/[^a-zA-Z0-9-\$\.]/-/g; lc} map {split /:/} @data;
85  
86 0 ▶ if ($item->isa('Zing::Channel')) {
Branch: 11 branches
BranchTrueFalseTotal
if ($item->isa('Zing::Channel')) { } 0 0 0
elsif ($item->isa('Zing::Data')) { } 0 0 0
elsif ($item->isa('Zing::Domain')) { } 0 0 0
elsif ($item->isa('Zing::Kernel')) { } 0 0 0
elsif ($item->isa('Zing::Mailbox')) { } 0 0 0
elsif ($item->isa('Zing::Process')) { } 0 0 0
elsif ($item->isa('Zing::Queue')) { } 0 0 0
elsif ($item->isa('Zing::Registry')) { } 0 0 0
elsif ($item->isa('Zing::KeyVal')) { } 0 0 0
elsif ($item->isa('Zing::PubSub')) { } 0 0 0
elsif ($item->isa('Zing::Repo')) { } 0 0 0
87 0 $args->{symbol} = $symbols->{'Zing::Channel'};
88 0 ▶ $args->{target} = $item->target eq 'global' ? 'global' : $local;
Branch: 1 branch
BranchTrueFalseTotal
$item->target eq 'global' ? : 0 0 0
89 0 $args->{bucket} = $item->name;
90 0 $args->{facets} = [@data];
91 }
92 elsif ($item->isa('Zing::Data')) {
93 0 my ($bucket, @facets) = split /:/, $item->name;
94 0 $args->{symbol} = $symbols->{'Zing::Data'};
95 0 $args->{target} = $local;
96 0 $args->{bucket} = $bucket;
97 0 $args->{facets} = [@facets, @data];
98 }
99 elsif ($item->isa('Zing::Domain')) {
100 0 $args->{symbol} = $symbols->{'Zing::Domain'};
101 0 ▶ $args->{target} = $item->channel->target eq 'global' ? 'global' : $local;
Branch: 1 branch
BranchTrueFalseTotal
$item->channel->target eq 'global' ? : 0 0 0
102 0 $args->{bucket} = $item->name;
103 0 $args->{facets} = [@data];
104 }
105 elsif ($item->isa('Zing::Kernel')) {
106 0 my ($bucket, @facets) = split /:/, $item->name;
107 0 $args->{symbol} = $symbols->{'Zing::Kernel'};
108 0 $args->{target} = $local;
109 0 $args->{bucket} = $bucket;
110 0 $args->{facets} = [@facets, @data];
111 }
112 elsif ($item->isa('Zing::Mailbox')) {
113 0 my ($bucket, @facets) = split /:/, $item->name;
114 0 $args->{symbol} = $symbols->{'Zing::Mailbox'};
115 0 $args->{target} = 'global';
116 0 $args->{bucket} = $bucket;
117 0 $args->{facets} = [@facets, @data];
118 }
119 elsif ($item->isa('Zing::Process')) {
120 0 my ($bucket, @facets) = split /:/, $item->name;
121 0 $args->{symbol} = $symbols->{'Zing::Process'};
122 0 $args->{target} = $local;
123 0 $args->{bucket} = $bucket;
124 0 $args->{facets} = [@facets, @data];
125 }
126 elsif ($item->isa('Zing::Queue')) {
127 0 $args->{symbol} = $symbols->{'Zing::Queue'};
128 0 ▶ $args->{target} = $item->target eq 'global' ? 'global' : $local;
Branch: 1 branch
BranchTrueFalseTotal
$item->target eq 'global' ? : 0 0 0
129 0 $args->{bucket} = $item->name;
130 0 $args->{facets} = [@data];
131 }
132 elsif ($item->isa('Zing::Registry')) {
133 0 $args->{symbol} = $symbols->{'Zing::Registry'};
134 0 ▶ $args->{target} = $item->target eq 'global' ? 'global' : $local;
Branch: 1 branch
BranchTrueFalseTotal
$item->target eq 'global' ? : 0 0 0
135 0 $args->{bucket} = $item->name;
136 0 $args->{facets} = [@data];
137 }
138 elsif ($item->isa('Zing::KeyVal')) {
139 0 $args->{symbol} = $symbols->{'Zing::KeyVal'};
140 0 ▶ $args->{target} = $item->target eq 'global' ? 'global' : $local;
Branch: 1 branch
BranchTrueFalseTotal
$item->target eq 'global' ? : 0 0 0
141 0 $args->{bucket} = $item->name;
142 0 $args->{facets} = [@data];
143 }
144 elsif ($item->isa('Zing::PubSub')) {
145 0 $args->{symbol} = $symbols->{'Zing::PubSub'};
146 0 ▶ $args->{target} = $item->target eq 'global' ? 'global' : $local;
Branch: 1 branch
BranchTrueFalseTotal
$item->target eq 'global' ? : 0 0 0
147 0 $args->{bucket} = $item->name;
148 0 $args->{facets} = [@data];
149 }
150 elsif ($item->isa('Zing::Repo')) {
151 0 $args->{symbol} = $symbols->{'Zing::Repo'};
152 0 ▶ $args->{target} = $item->target eq 'global' ? 'global' : $local;
Branch: 1 branch
BranchTrueFalseTotal
$item->target eq 'global' ? : 0 0 0
153 0 $args->{bucket} = $item->name;
154 0 $args->{facets} = [@data];
155 }
156 else {
157 0 Carp::confess qq(Error in term: Unrecognizable "object");
158 }
159 0 ▶ $args->{handle} = $ENV{ZING_NS} || 'main';
Condition0%0/2
$ENV{'ZING_NS'} || 'main'
l!l
00
MC/DC0%0/1
$ENV{'ZING_NS'} || 'main'
$ENV{'ZING_NS'}
Truth table0%0/2
A
A= $ENV{'ZING_NS'}
Aresult
11
00
160 0 $args->{system} = 'zing';
161 }
162 ▶ elsif(defined $item && !ref $item) {
Condition0%0/3
defined $item and not ref $item
!ll&&!rl&&r
000
MC/DC0%0/2
defined $item and not ref $item
defined $item not ref $item
Truth table0%0/3
A and not(B)
A= defined $itemB= not ref $item
ABresult
0X0
100
111
163 0 my $schema = [split /:/, "$item", 6];
164  
165 0 my $system = $schema->[0];
166 0 my $handle = $schema->[1];
167 0 my $target = $schema->[2];
168 0 my $symbol = $schema->[3];
169 0 my $bucket = $schema->[4];
170 0 my $extras = $schema->[5];
171  
172 0 ▶ my $facets = [split /:/, $extras || ''];
Condition0%0/2
$extras || ''
l!l
00
MC/DC0%0/1
$extras || ''
$extras
Truth table0%0/2
A
A= $extras
Aresult
11
00
173  
174 0 ▶ unless ($system eq 'zing') {
Branch: 1 branch
BranchTrueFalseTotal
unless ($system eq "zing") 0 0 0
175 0 Carp::confess qq(Error in term: Unrecognizable "system" in: $item);
176 }
177 0 ▶ unless ($target =~ m{^(global|local\(\d+\.\d+\.\d+\.\d+\))$}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($target =~ /^(global|local\(\d+\.\d+\.\d+\.\d+\))$/u) 0 0 0
178 0 Carp::confess qq(Error in term: Unrecognizable "target" ($target) in: $item);
179 }
180 0 ▶ unless (grep {$_ eq $symbol} values %$symbols) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {$_ eq $symbol;} values %$symbols) 0 0 0
181 0 Carp::confess qq(Error in term: Unrecognizable "symbol" ($symbol) in: $item);
182 }
183  
184 0 $args->{system} = $system;
185 0 $args->{handle} = $handle;
186 0 $args->{target} = $target;
187 0 $args->{symbol} = $symbol;
188 0 $args->{bucket} = $bucket;
189 0 $args->{facets} = $facets;
190 }
191 else {
192 0 Carp::confess 'Unrecognizable Zing term provided';
193 }
194  
195 0 return $args;
196 49 }
197  
198 # METHODS
199  
200 0 ▶method channel() {
Subroutine channel: not called CC=2 SCAR=17.9
Pod documented
201 0 ▶ unless ($self->symbol eq 'channel') {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->symbol eq "channel") 0 0 0
202 0 Carp::confess 'Error in term: not a "channel"';
203 }
204  
205 0 return $self->string;
206 49 }
207  
208 0 ▶method data() {
Subroutine data: not called CC=2 SCAR=17.9
Pod documented
209 0 ▶ unless ($self->symbol eq 'data') {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->symbol eq "data") 0 0 0
210 0 Carp::confess 'Error in term: not a "data" term';
211 }
212  
213 0 return $self->string;
214 49 }
215  
216 0 ▶method domain() {
Subroutine domain: not called CC=2 SCAR=17.9
Pod documented
217 0 ▶ unless ($self->symbol eq 'domain') {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->symbol eq "domain") 0 0 0
218 0 Carp::confess 'Error in term: not a "domain" term';
219 }
220  
221 0 return $self->string;
222 49 }
223  
224 0 ▶method kernel() {
Subroutine kernel: not called CC=2 SCAR=17.9
Pod documented
225 0 ▶ unless ($self->symbol eq 'kernel') {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->symbol eq "kernel") 0 0 0
226 0 Carp::confess 'Error in term: not a "kernel" term';
227 }
228  
229 0 return $self->string;
230 49 }
231  
232 0 ▶method keyval() {
Subroutine keyval: not called CC=2 SCAR=17.9
Pod documented
233 0 ▶ unless ($self->symbol eq 'keyval') {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->symbol eq "keyval") 0 0 0
234 0 Carp::confess 'Error in term: not a "keyval" term';
235 }
236  
237 0 return $self->string;
238 49 }
239  
240 0 ▶method mailbox() {
Subroutine mailbox: not called CC=2 SCAR=17.9
Pod documented
241 0 ▶ unless ($self->symbol eq 'mailbox') {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->symbol eq "mailbox") 0 0 0
242 0 Carp::confess 'Error in term: not a "mailbox" term';
243 }
244  
245 0 return $self->string;
246 49 }
247  
248 0 ▶method process() {
Subroutine process: not called CC=2 SCAR=17.9
Pod documented
249 0 ▶ unless ($self->symbol eq 'process') {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->symbol eq "process") 0 0 0
250 0 Carp::confess 'Error in term: not a "process" term';
251 }
252  
253 0 return $self->string;
254 49 }
255  
256 0 ▶method pubsub() {
Subroutine pubsub: not called CC=2 SCAR=17.9
Pod documented
257 0 ▶ unless ($self->symbol eq 'pubsub') {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->symbol eq "pubsub") 0 0 0
258 0 Carp::confess 'Error in term: not a "pubsub" term';
259 }
260  
261 0 return $self->string;
262 49 }
263  
264 0 ▶method queue() {
Subroutine queue: not called CC=2 SCAR=17.9
Pod documented
265 0 ▶ unless ($self->symbol eq 'queue') {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->symbol eq "queue") 0 0 0
266 0 Carp::confess 'Error in term: not a "queue" term';
267 }
268  
269 0 return $self->string;
270 49 }
271  
272 0 ▶method registry() {
Subroutine registry: not called CC=2 SCAR=17.9
Pod documented
273 0 ▶ unless ($self->symbol eq 'registry') {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->symbol eq "registry") 0 0 0
274 0 Carp::confess 'Error in term: not a "registry" term';
275 }
276  
277 0 return $self->string;
278 49 }
279  
280 0 ▶method repo() {
Subroutine repo: not called CC=2 SCAR=17.9
Pod documented
281 0 ▶ unless ($self->symbol eq 'repo') {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->symbol eq "repo") 0 0 0
282 0 Carp::confess 'Error in term: not a "repo" term';
283 }
284  
285 0 return $self->string;
286 49 }
287  
288 0 ▶method string() {
Subroutine string: not called CC=2 SCAR=17.9
Pod documented
289 0 my $system = $self->system;
290 0 my $handle = $self->handle;
291 0 my $target = $self->target;
292 0 my $symbol = $self->symbol;
293 0 my $bucket = $self->bucket;
294 0 ▶ my $facets = $self->facets || [];
Condition0%0/2
$self->facets || []
l!l
00
MC/DC0%0/1
$self->facets || []
$self->facets
Truth table0%0/2
A
A= $self->facets
Aresult
11
00
295  
296 0 return lc join ':', $system, $handle, $target, $symbol, $bucket, @$facets;
297 49 }
298  
299 49 1;
300  
301 =encoding utf8
302  
303 =head1 NAME
304  
305 Zing::Term - Resource Representation
306  
307 =cut
308  
309 =head1 ABSTRACT
310  
311 Resource Representation
312  
313 =cut
314  
315 =head1 SYNOPSIS
316  
317 use Zing::KeyVal;
318 use Zing::Term;
319  
320 my $term = Zing::Term->new(Zing::KeyVal->new(name => 'nodes'));
321  
322 # $term->keyval;
323  
324 =cut
325  
326 =head1 DESCRIPTION
327  
328 This package provides a mechanism for generating and validating (global and
329 local) resource identifiers.
330  
331 =cut
332  
333 =head1 LIBRARIES
334  
335 This package uses type constraints from:
336  
337 L<Zing::Types>
338  
339 =cut
340  
341 =head1 ATTRIBUTES
342  
343 This package has the following attributes:
344  
345 =cut
346  
347 =head2 bucket
348  
349 bucket(Str)
350  
351 This attribute is read-only, accepts C<(Str)> values, and is required.
352  
353 =cut
354  
355 =head2 facets
356  
357 facets(ArrayRef[Str])
358  
359 This attribute is read-only, accepts C<(ArrayRef[Str])> values, and is optional.
360  
361 =cut
362  
363 =head2 handle
364  
365 handle(Str)
366  
367 This attribute is read-only, accepts C<(Str)> values, and is required.
368  
369 =cut
370  
371 =head2 symbol
372  
373 symbol(Str)
374  
375 This attribute is read-only, accepts C<(Str)> values, and is required.
376  
377 =cut
378  
379 =head2 system
380  
381 system(Str)
382  
383 This attribute is read-only, accepts C<(Str)> values, and is required.
384  
385 =cut
386  
387 =head2 target
388  
389 target(Str)
390  
391 This attribute is read-only, accepts C<(Str)> values, and is required.
392  
393 =cut
394  
395 =head1 METHODS
396  
397 This package implements the following methods:
398  
399 =cut
400  
401 =head2 channel
402  
403 channel() : Str
404  
405 The channel method validates and returns a "channel" resource identifier.
406  
407 =over 4
408  
409 =item channel example #1
410  
411 use Zing::Channel;
412  
413 Zing::Term->new(Zing::Channel->new(name => 'chat'));
414  
415 # $term->channel;
416  
417 =back
418  
419 =cut
420  
421 =head2 data
422  
423 data() : Str
424  
425 The data method validates and returns a "data" resource identifier.
426  
427 =over 4
428  
429 =item data example #1
430  
431 use Zing::Data;
432 use Zing::Process;
433  
434 Zing::Term->new(Zing::Data->new(process => Zing::Process->new));
435  
436 # $term->data;
437  
438 =back
439  
440 =cut
441  
442 =head2 domain
443  
444 domain() : Str
445  
446 The domain method validates and returns a "domain" resource identifier.
447  
448 =over 4
449  
450 =item domain example #1
451  
452 use Zing::Domain;
453  
454 Zing::Term->new(Zing::Domain->new(name => 'transaction'));
455  
456 # $term->domain;
457  
458 =back
459  
460 =cut
461  
462 =head2 kernel
463  
464 kernel() : Str
465  
466 The kernel method validates and returns a "kernel" resource identifier.
467  
468 =over 4
469  
470 =item kernel example #1
471  
472 use Zing::Kernel;
473  
474 Zing::Term->new(Zing::Kernel->new(scheme => ['MyApp', [], 1]));
475  
476 # $term->kernel;
477  
478 =back
479  
480 =cut
481  
482 =head2 keyval
483  
484 keyval() : Str
485  
486 The keyval method validates and returns a "keyval" resource identifier.
487  
488 =over 4
489  
490 =item keyval example #1
491  
492 use Zing::KeyVal;
493  
494 Zing::Term->new(Zing::KeyVal->new(name => 'listeners'));
495  
496 # $term->keyval;
497  
498 =back
499  
500 =cut
501  
502 =head2 mailbox
503  
504 mailbox() : Str
505  
506 The mailbox method validates and returns a "mailbox" resource identifier.
507  
508 =over 4
509  
510 =item mailbox example #1
511  
512 use Zing::Mailbox;
513 use Zing::Process;
514  
515 Zing::Term->new(Zing::Mailbox->new(process => Zing::Process->new));
516  
517 # $term->mailbox;
518  
519 =back
520  
521 =cut
522  
523 =head2 process
524  
525 process() : Str
526  
527 The process method validates and returns a "process" resource identifier.
528  
529 =over 4
530  
531 =item process example #1
532  
533 use Zing::Process;
534  
535 Zing::Term->new(Zing::Process->new);
536  
537 # $term->process;
538  
539 =back
540  
541 =cut
542  
543 =head2 pubsub
544  
545 pubsub() : Str
546  
547 The pubsub method validates and returns a "pubsub" resource identifier.
548  
549 =over 4
550  
551 =item pubsub example #1
552  
553 use Zing::PubSub;
554  
555 Zing::Term->new(Zing::PubSub->new(name => 'operations'));
556  
557 # $term->pubsub;
558  
559 =back
560  
561 =cut
562  
563 =head2 queue
564  
565 queue() : Str
566  
567 The queue method validates and returns a "queue" resource identifier.
568  
569 =over 4
570  
571 =item queue example #1
572  
573 use Zing::Queue;
574  
575 Zing::Term->new(Zing::Queue->new(name => 'workflows'));
576  
577 # $term->queue;
578  
579 =back
580  
581 =cut
582  
583 =head2 registry
584  
585 registry() : Str
586  
587 The registry method validates and returns a "registry" resource identifier.
588  
589 =over 4
590  
591 =item registry example #1
592  
593 use Zing::Registry;
594  
595 Zing::Term->new(Zing::Registry->new(name => 'campaigns'));
596  
597 # $term->registry;
598  
599 =back
600  
601 =cut
602  
603 =head2 repo
604  
605 repo() : Str
606  
607 The repo method validates and returns a "repo" resource identifier.
608  
609 =over 4
610  
611 =item repo example #1
612  
613 use Zing::Repo;
614  
615 Zing::Term->new(Zing::Repo->new(name => 'miscellaneous'));
616  
617 # $term->repo;
618  
619 =back
620  
621 =cut
622  
623 =head2 string
624  
625 string() : Str
626  
627 The string method returns a resource identifier. This method is called
628 automatically when the object is used as a string.
629  
630 =over 4
631  
632 =item string example #1
633  
634 # given: synopsis
635  
636 $term->string;
637  
638 =back
639  
640 =cut
641  
642 =head1 AUTHOR
643  
644 Al Newkirk, C<awncorp@cpan.org>
645  
646 =head1 LICENSE
647  
648 Copyright (C) 2011-2019, Al Newkirk, et al.
649  
650 This is free software; you can redistribute it and/or modify it under the terms
651 of the The Apache License, Version 2.0, as elucidated in the L<"license
652 file"|https://github.com/iamalnewkirk/zing/blob/master/LICENSE>.
653  
654 =head1 PROJECT
655  
656 L<Wiki|https://github.com/iamalnewkirk/zing/wiki>
657  
658 L<Project|https://github.com/iamalnewkirk/zing>
659  
660 L<Initiatives|https://github.com/iamalnewkirk/zing/projects>
661  
662 L<Milestones|https://github.com/iamalnewkirk/zing/milestones>
663  
664 L<Contributing|https://github.com/iamalnewkirk/zing/blob/master/CONTRIBUTE.md>
665  
666 L<Issues|https://github.com/iamalnewkirk/zing/issues>
667  
668 =cut
↑ Summary Zing/Cli.pm »