File Coverage

blib/lib/Data/Object/Space.pm
Criterion Covered Total %
statement 419 446 93.9
branch 56 78 71.7
condition 11 24 45.8
subroutine 74 78 94.8
pod 48 49 97.9
total 608 675 90.0


line stmt bran cond sub pod time code
1             package Data::Object::Space;
2              
3 1     1   107008 use 5.014;
  1         4  
4              
5 1     1   7 use strict;
  1         2  
  1         21  
6 1     1   4 use warnings;
  1         1  
  1         33  
7 1     1   5 use routines;
  1         1  
  1         8  
8              
9 1     1   1527 use parent 'Data::Object::Name';
  1         2  
  1         7  
10              
11             our $VERSION = '2.09'; # VERSION
12              
13             # METHODS
14              
15             my %has;
16              
17 1     1 1 164288 method all($name, @args) {
  1         3  
  1         2  
18 1         2 my $result = [];
19              
20 1         5 my $class = $self->class;
21 1         8 for my $package ($self->package, @{$self->inherits}) {
  1         57  
22 2         45 push @$result, [$package, $class->new($package)->$name(@args)];
23             }
24              
25 1         33 return $result;
26             }
27              
28 4     4 1 25500 method append(@args) {
  4         14  
  4         7  
29 4         14 my $class = $self->class;
30              
31 4         22 my $path = join '/',
32             $self->path, map $class->new($_)->path, @args;
33              
34 4         415 return $class->new($path);
35             }
36              
37 4     4 1 5382 method array($name) {
  4         14  
  4         6  
38 1     1   3359 no strict 'refs';
  1         3  
  1         54  
39              
40 4         20 my $class = $self->package;
41              
42 4         156 return [@{"${class}::${name}"}];
  4         46  
43             }
44              
45 2     2 1 5320 method arrays() {
  2         4  
46 1     1   59 no strict 'refs';
  1         2  
  1         110  
47              
48 2         8 my $class = $self->package;
49              
50             my $arrays = [
51 6         28 sort grep !!@{"${class}::$_"},
52 2         89 grep /^[_a-zA-Z]\w*$/, keys %{"${class}::"}
  2         20  
53             ];
54              
55 2         15 return $arrays;
56             }
57              
58 2     2 1 12041 method authority() {
  2         4  
59              
60 2         9 return $self->scalar('AUTHORITY');
61             }
62              
63 2     2 1 6318 method base() {
  2         5  
64              
65 2         9 return $self->parse->[-1];
66             }
67              
68 6 100   6 1 25093 method bless($data = {}) {
  6         29  
  6         11  
69 6         21 my $class = $self->load;
70              
71 6         41 return CORE::bless $data, $class;
72             }
73              
74 2     2 1 10842 method build(@args) {
  2         5  
  2         3  
75 2         6 my $class = $self->load;
76              
77 2         7 return $self->call('new', $class, @args);
78             }
79              
80 4     4 1 11377 method call($func, @args) {
  4         10  
  4         7  
81 4         11 my $class = $self->load;
82              
83 4 50       10 unless ($func) {
84 0         0 require Carp;
85              
86 0         0 my $text = qq[Attempt to call undefined class method in package "$class"];
87              
88 0         0 Carp::confess $text;
89             }
90              
91 4         17 my $next = $class->can($func);
92              
93 4 100       13 unless ($next) {
94 1 50       5 if ($class->can('AUTOLOAD')) {
95 1     1   407 $next = sub { no strict 'refs'; &{"${class}::${func}"}(@args) };
  1     1   2  
  1         120  
  1         6  
  1         2  
  1         24  
96             }
97             }
98              
99 4 50       9 unless ($next) {
100 0         0 require Carp;
101              
102 0         0 my $text = qq[Unable to locate class method "$func" via package "$class"];
103              
104 0         0 Carp::confess $text;
105             }
106              
107 4         8 @_ = @args; goto $next;
  4         61  
108             }
109              
110 3     3 1 16233 method chain(@steps) {
  3         9  
  3         5  
111 3         5 my $result = $self;
112              
113 3         8 for my $step (@steps) {
114 5 100       19 my ($name, @args) = (ref($step) eq 'ARRAY') ? @$step : ($step);
115              
116 5         48 $result = $result->$name(@args);
117             }
118              
119 3         33 return $result;
120             }
121              
122 1     1 1 5828 method child(@args) {
  1         3  
  1         965  
123              
124 1         6 return $self->append(@args);
125             }
126              
127 1     1 1 5539 method children() {
  1         2  
128 1         4 my %list;
129             my $path;
130 1         0 my $type;
131              
132 1         5 $path = quotemeta $self->path;
133 1         56 $type = 'pm';
134              
135 1         34 my $regexp = qr/$path\/[^\/]+\.$type/;
136              
137 1         59 for my $item (keys %INC) {
138 157 50       350 $list{$item}++ if $item =~ /$regexp$/;
139             }
140              
141 1         7 my %seen;
142              
143 1         4 for my $dir (@INC) {
144 11 100       436 next if $seen{$dir}++;
145              
146 9         18 my $re = quotemeta $dir;
147 27         589 map { s/^$re\///; $list{$_}++ }
  27         66  
148 9         20 grep !$list{$_}, glob "$dir/@{[$self->path]}/*.$type";
  9         24  
149             }
150              
151 1         67 my $class = $self->class;
152              
153             return [
154             map $class->new($_),
155 1         14 map {s/(.*)\.$type$/$1/r}
  27         122  
156             sort keys %list
157             ];
158             }
159              
160 14     14 0 32 method class() {
  14         23  
161              
162 14         37 return ref $self;
163             }
164              
165 1     1 1 2 method cop($func, @args) {
  1         4  
  1         2  
166 1         3 my $class = $self->load;
167              
168 1 50       4 unless ($func) {
169 0         0 require Carp;
170              
171 0         0 my $text = qq[Attempt to cop undefined object method from package "$class"];
172              
173 0         0 Carp::confess $text;
174             }
175              
176 1         7 my $next = $class->can($func);
177              
178 1 50       5 unless ($next) {
179 0         0 require Carp;
180              
181 0         0 my $text = qq[Unable to locate object method "$func" via package "$class"];
182              
183 0         0 Carp::confess $text;
184             }
185              
186 1 50   1   13 return sub { $next->(@args ? (@args, @_) : @_) };
  1         660  
187             }
188              
189 1     1 1 7015 method data() {
  1         2  
190 1     1   789 no strict 'refs';
  1         3  
  1         139  
191              
192 1         5 my $class = $self->package;
193              
194 1         41 local $.;
195              
196 1         3 my $handle = \*{"${class}::DATA"};
  1         9  
197              
198 1 50       13 return '' if !fileno $handle;
199              
200 0         0 seek $handle, 0, 0;
201              
202 0         0 my $data = join '', <$handle>;
203              
204 0         0 $data =~ s/^.*\n__DATA__\r?\n/\n/s;
205 0         0 $data =~ s/\n__END__\r?\n.*$/\n/s;
206              
207 0         0 return $data;
208             }
209              
210 1     1 1 8 method destroy() {
  1         1  
211 1         6 require Symbol;
212              
213 1         20 Symbol::delete_package($self->package);
214              
215 1         525 my $c_re = quotemeta $self->package;
216 1         37 my $p_re = quotemeta $self->path;
217              
218 1         64 map {delete $has{$_}} grep /^$c_re/, keys %has;
  1         4  
219 1         133 map {delete $INC{$_}} grep /^$p_re/, keys %INC;
  1         4  
220              
221 1         16 return $self;
222             }
223              
224 8     8 1 4996 method eval(@args) {
  8         19  
  8         11  
225 8         12 local $@;
226              
227 1     1   101 my $result = eval join ' ', map "$_", "package @{[$self->package]};", @args;
  1     1   2  
  1     1   80  
  1         114  
  1         2  
  1         52  
  1         94  
  1         2  
  1         84  
  8         21  
  8         24  
228              
229 8 100       207 Carp::confess $@ if $@;
230              
231 7         77 return $result;
232             }
233              
234 1     1 1 7822 method functions() {
  1         2  
235 1         2 my @functions;
236              
237 1     1   331 no strict 'refs';
  1         3  
  1         118  
238              
239 1         533 require Function::Parameters::Info;
240              
241 1         1739 my $class = $self->package;
242 1         55 for my $routine (@{$self->routines}) {
  1         5  
243 1 50       14 my $code = $class->can($routine) or next;
244 1         6 my $data = Function::Parameters::info($code);
245              
246 1 50 33     84 push @functions, $routine if $data && !$data->invocant;
247             }
248              
249 1         33 return [sort @functions];
250             }
251              
252 1     1 1 5939 method hash($name) {
  1         3  
  1         3  
253 1     1   65 no strict 'refs';
  1         2  
  1         56  
254              
255 1         5 my $class = $self->package;
256              
257 1         49 return {%{"${class}::${name}"}};
  1         15  
258             }
259              
260 2     2 1 5739 method hashes() {
  2         4  
261 1     1   61 no strict 'refs';
  1         2  
  1         102  
262              
263 2         7 my $class = $self->package;
264              
265             return [
266 13         43 sort grep !!%{"${class}::$_"},
267 2         77 grep /^[_a-zA-Z]\w*$/, keys %{"${class}::"}
  2         21  
268             ];
269             }
270              
271 3     3 1 5456 method id() {
  3         7  
272              
273 3         11 return $self->label;
274             }
275              
276 1     1 1 6090 method init() {
  1         3  
277 1         5 my $class = $self->package;
278              
279 1 50       43 if ($self->routine('import')) {
280              
281 0         0 return $class;
282             }
283              
284 1 50       4 $class = $self->locate ? $self->load : $self->package;
285              
286 1 50       29 if ($self->routine('import')) {
287              
288 0         0 return $class;
289             }
290             else {
291              
292 1     0   6 my $import = sub { $class };
  0     0   0  
293              
294 1         5 $self->inject('import', $import);
295 1         6 $self->load;
296              
297 1         9 return $class;
298             }
299             }
300              
301 3     3 1 12175 method inherits() {
  3         8  
302              
303 3         56 return $self->array('ISA');
304             }
305              
306 2     2 1 5878 method included() {
  2         4  
307              
308 2         17 return $INC{$self->format('path', '%s.pm')};
309             }
310              
311 2     2 1 5899 method inject($name, $coderef) {
  2         7  
  2         3  
312 2         6 my $class = $self->package;
313              
314 2         66 local $@;
315 1     1   393 no strict 'refs';
  1         2  
  1         31  
316 1     1   6 no warnings 'redefine';
  1         2  
  1         168  
317              
318 2 50       63 if (state $subutil = eval "require Sub::Util") {
319 2         23 return *{"${class}::${name}"} = Sub::Util::set_subname(
320 0     0   0 "${class}::${name}", $coderef || sub{$class}
321 2   50     19 );
322             }
323             else {
324 0   0 0   0 return *{"${class}::${name}"} = $coderef || sub{$class};
  0         0  
  0         0  
325             }
326             }
327              
328 22     22 1 22045 method load() {
  22         41  
329 22         71 my $class = $self->package;
330              
331 22 100       841 return $class if $has{$class};
332              
333 15 50       56 if ($class eq "main") {
334 0         0 return do { $has{$class} = 1; $class };
  0         0  
  0         0  
335             }
336              
337 15   33     128 my $failed = !$class || $class !~ /^\w(?:[\w:']*\w)?$/;
338 15         46 my $loaded;
339              
340 15 50       41 my $error = do {
341 15         35 local $@;
342 1     1   199 no strict 'refs';
  1         2  
  1         115  
343 15         202 $loaded = !!$class->can('new');
344 15 100       94 $loaded = !!$class->can('import') if !$loaded;
345 15 100       83 $loaded = !!$class->can('meta') if !$loaded;
346 15 100       66 $loaded = !!$class->can('with') if !$loaded;
347 15 100       408 $loaded = eval "require $class; 1" if !$loaded;
348 15         101 $@;
349             }
350             if !$failed;
351              
352 15 50 66     143 do {
      66        
353 1         3 require Carp;
354              
355 1   50     4 my $message = $error || "cause unknown";
356              
357 1         276 Carp::confess "Error attempting to load $class: $message";
358             }
359             if $error
360             or $failed
361             or not $loaded;
362              
363 14         44 $has{$class} = 1;
364              
365 14         165 return $class;
366             }
367              
368 3     3 1 9530 method loaded() {
  3         9  
369 3         26 my $class = $self->package;
370 3         227 my $pexpr = $self->format('path', '%s.pm');
371              
372 3         202 my $is_loaded_eval = $has{$class};
373 3         8 my $is_loaded_used = $INC{$pexpr};
374              
375 3 100 66     49 return ($is_loaded_eval || $is_loaded_used) ? 1 : 0;
376             }
377              
378 3     3 1 10803 method locate() {
  3         12  
379 3         11 my $found = '';
380              
381 3         14 my $file = $self->format('path', '%s.pm');
382              
383 3         196 for my $path (@INC) {
384 31 100       682 do { $found = "$path/$file"; last } if -f "$path/$file";
  1         7  
  1         3  
385             }
386              
387 3         32 return $found;
388             }
389              
390 1     1 1 7322 method methods() {
  1         5  
391 1         6 my @methods;
392              
393 1     1   257 no strict 'refs';
  1         29  
  1         111  
394              
395 1         8 require Function::Parameters::Info;
396              
397 1         11 my $class = $self->package;
398 1         44 for my $routine (@{$self->routines}) {
  1         17  
399 1 50       22 my $code = $class->can($routine) or next;
400 1         7 my $data = Function::Parameters::info($code);
401              
402 1 50 33     168 push @methods, $routine if $data && $data->invocant;
403             }
404              
405 1         116 return [sort @methods];
406             }
407              
408 1     1 1 5700 method name() {
  1         8  
409              
410 1         6 return $self->package;
411             }
412              
413 3     3 1 5490 method parent() {
  3         6  
414 3         6 my @parts = @{$self->parse};
  3         15  
415              
416 3 50       206 pop @parts if @parts > 1;
417              
418 3         19 my $class = $self->class;
419              
420 3         11 return $class->new(join '/', @parts);
421             }
422              
423 14     14 1 27253 method parse() {
  14         25  
424              
425             return [
426 14         47 map ucfirst,
427             map join('', map(ucfirst, split /[-_]/)),
428             split /[^-_a-zA-Z0-9.]+/,
429             $self->path
430             ];
431             }
432              
433 3     3 1 16264 method parts() {
  3         5  
434              
435 3         9 return $self->parse;
436             }
437              
438 3     3 1 10916 method prepend(@args) {
  3         10  
  3         4  
439 3         9 my $class = $self->class;
440              
441 3         10 my $path = join '/',
442             (map $class->new($_)->path, @args), $self->path;
443              
444 3         265 return $class->new($path);
445             }
446              
447 1     1 1 5451 method rebase(@args) {
  1         4  
  1         2  
448 1         5 my $class = $self->class;
449              
450 1         7 my $path = join '/', map $class->new($_)->path, @args;
451              
452 1         63 return $class->new($self->base)->prepend($path);
453             }
454              
455 2     2 1 14136 method reload() {
  2         4  
456 2         9 my $class = $self->package;
457              
458 2         108 delete $has{$class};
459              
460 2         18 my $path = $self->format('path', '%s.pm');
461              
462 2         129 delete $INC{$path};
463              
464 2         14 return $self->load;
465             }
466              
467 4     4 1 5423 method require($target) {
  4         10  
  4         7  
468 4 50       101 $target = "'$target'" if -f $target;
469              
470 4         35 return $self->eval("require $target");
471             }
472              
473 1     1 1 4805 method root() {
  1         8  
474              
475 1         6 return $self->parse->[0];
476             }
477              
478 3     3 1 5582 method routine($name) {
  3         8  
  3         3  
479 1     1   755 no strict 'refs';
  1         2  
  1         48  
480              
481 3         9 my $class = $self->package;
482              
483 3         73 return *{"${class}::${name}"}{"CODE"};
  3         34  
484             }
485              
486 3     3 1 13288 method routines() {
  3         8  
487 1     1   65 no strict 'refs';
  1         3  
  1         91  
488              
489 3         11 my $class = $self->package;
490              
491             return [
492 8         44 sort grep *{"${class}::$_"}{"CODE"},
493 3         108 grep /^[_a-zA-Z]\w*$/, keys %{"${class}::"}
  3         32  
494             ];
495             }
496              
497 5     5 1 5854 method scalar($name) {
  5         12  
  5         9  
498 1     1   82 no strict 'refs';
  1         2  
  1         54  
499              
500 5         18 my $class = $self->package;
501              
502 5         201 return ${"${class}::${name}"};
  5         61  
503             }
504              
505 2     2 1 4942 method scalars() {
  2         89  
506 1     1   66 no strict 'refs';
  1         8  
  1         151  
507              
508 2         9 my $class = $self->package;
509              
510             return [
511 16         117 sort grep defined ${"${class}::$_"},
512 2         67 grep /^[_a-zA-Z]\w*$/, keys %{"${class}::"}
  2         28  
513             ];
514             }
515              
516 1     1 1 5378 method sibling(@args) {
  1         3  
  1         2  
517              
518 1         5 return $self->parent->append(@args);
519             }
520              
521 1     1 1 5433 method siblings() {
  1         3  
522 1         5 my %list;
523             my $path;
524 1         0 my $type;
525              
526 1         4 $path = quotemeta $self->parent->path;
527 1         21 $type = 'pm';
528              
529 1         42 my $regexp = qr/$path\/[^\/]+\.$type/;
530              
531 1         176 for my $item (keys %INC) {
532 221 100       463 $list{$item}++ if $item =~ /$regexp$/;
533             }
534              
535 1         9 my %seen;
536              
537 1         4 for my $dir (@INC) {
538 13 100       709 next if $seen{$dir}++;
539              
540 10         21 my $re = quotemeta $dir;
541 2         227 map { s/^$re\///; $list{$_}++ }
  2         10  
542 10         19 grep !$list{$_}, glob "$dir/@{[$self->path]}/*.$type";
  10         30  
543             }
544              
545 1         5 my $class = $self->class;
546              
547             return [
548             map $class->new($_),
549 1         8 map {s/(.*)\.$type$/$1/r}
  5         47  
550             sort keys %list
551             ];
552             }
553              
554 2     2 1 13775 method tryload() {
  2         3  
555              
556 2         3 return do { local $@; eval { $self->load }; int!$@ };
  2         3  
  2         5  
  2         7  
  2         646  
557             }
558              
559 3     3 1 19015 method use($target, @params) {
  3         8  
  3         6  
560 3         5 my $version;
561              
562 3         8 my $class = $self->package;
563              
564 3 100       123 ($target, $version) = @$target if ref $target eq 'ARRAY';
565              
566 3         11 $self->require($target);
567              
568 3         10 require Scalar::Util;
569              
570 3 100       38 my @statement = (
571             'no strict "subs";',
572             (
573             Scalar::Util::looks_like_number($version)
574             ? "${target}->VERSION($version);" : ()
575             ),
576             'sub{ my ($target, @params) = @_; $target->import(@params)}'
577             );
578              
579 3         16 $self->eval(join("\n", @statement))->($target, $class, @params);
580              
581 2         800 return $self;
582             }
583              
584 4     4 1 14531 method used() {
  4         8  
585 4         12 my $class = $self->package;
586 4         143 my $path = $self->path;
587 4         166 my $regexp = quotemeta $path;
588              
589 4 100       33 return $path if $has{$class};
590              
591 2         122 for my $item (keys %INC) {
592 381 50       745 return $path if $item =~ /$regexp\.pm$/;
593             }
594              
595 2         32 return '';
596             }
597              
598 1     1 1 5604 method variables() {
  1         2  
599              
600 1         4 return [map [$_, [sort @{$self->$_}]], qw(arrays hashes scalars)];
  3         14  
601             }
602              
603 2     2 1 18826 method version() {
  2         5  
604              
605 2         6 return $self->scalar('VERSION');
606             }
607              
608             1;
609              
610             =encoding utf8
611              
612             =head1 NAME
613              
614             Data::Object::Space - Namespace Class
615              
616             =cut
617              
618             =head1 ABSTRACT
619              
620             Namespace Class for Perl 5
621              
622             =cut
623              
624             =head1 SYNOPSIS
625              
626             package main;
627              
628             use Data::Object::Space;
629              
630             my $space = Data::Object::Space->new('foo/bar');
631              
632             =cut
633              
634             =head1 DESCRIPTION
635              
636             This package provides methods for parsing and manipulating package namespaces.
637              
638             =cut
639              
640             =head1 INHERITS
641              
642             This package inherits behaviors from:
643              
644             L<Data::Object::Name>
645              
646             =cut
647              
648             =head1 LIBRARIES
649              
650             This package uses type constraints from:
651              
652             L<Types::Standard>
653              
654             =cut
655              
656             =head1 METHODS
657              
658             This package implements the following methods:
659              
660             =cut
661              
662             =head2 all
663              
664             all(Str $name, Any @args) : ArrayRef[Tuple[Str, Any]]
665              
666             The all method executes any available method on the instance and all instances
667             representing packages inherited by the package represented by the invocant.
668              
669             =over 4
670              
671             =item all example #1
672              
673             package main;
674              
675             use Data::Object::Space;
676              
677             my $space = Data::Object::Space->new('data/object/space');
678              
679             $space->all('id');
680              
681             # [
682             # ['Data::Object::Space', 'Data_Object_Space'],
683             # ['Data::Object::Name', 'Data_Object_Name'],
684             # ]
685              
686             =back
687              
688             =cut
689              
690             =head2 append
691              
692             append(Str @args) : Object
693              
694             The append method modifies the object by appending to the package namespace
695             parts.
696              
697             =over 4
698              
699             =item append example #1
700              
701             # given: synopsis
702              
703             $space->append('baz');
704              
705             # 'Foo/Bar/Baz'
706              
707             =back
708              
709             =over 4
710              
711             =item append example #2
712              
713             # given: synopsis
714              
715             $space->append('baz', 'bax');
716              
717             # $space->package;
718              
719             # 'Foo/Bar/Baz/Bax'
720              
721             =back
722              
723             =cut
724              
725             =head2 array
726              
727             array(Str $arg1) : ArrayRef
728              
729             The array method returns the value for the given package array variable name.
730              
731             =over 4
732              
733             =item array example #1
734              
735             # given: synopsis
736              
737             package Foo::Bar;
738              
739             our @handler = 'start';
740              
741             package main;
742              
743             $space->array('handler')
744              
745             # ['start']
746              
747             =back
748              
749             =cut
750              
751             =head2 arrays
752              
753             arrays() : ArrayRef
754              
755             The arrays method searches the package namespace for arrays and returns their
756             names.
757              
758             =over 4
759              
760             =item arrays example #1
761              
762             # given: synopsis
763              
764             package Foo::Bar;
765              
766             our @handler = 'start';
767             our @initial = ('next', 'prev');
768              
769             package main;
770              
771             $space->arrays
772              
773             # ['handler', 'initial']
774              
775             =back
776              
777             =cut
778              
779             =head2 authority
780              
781             authority() : Maybe[Str]
782              
783             The authority method returns the C<AUTHORITY> declared on the target package,
784             if any.
785              
786             =over 4
787              
788             =item authority example #1
789              
790             package Foo::Boo;
791              
792             package main;
793              
794             use Data::Object::Space;
795              
796             my $space = Data::Object::Space->new('foo/boo');
797              
798             $space->authority
799              
800             # undef
801              
802             =back
803              
804             =over 4
805              
806             =item authority example #2
807              
808             package Foo::Boo;
809              
810             our $AUTHORITY = 'cpan:AWNCORP';
811              
812             package main;
813              
814             use Data::Object::Space;
815              
816             my $space = Data::Object::Space->new('foo/boo');
817              
818             $space->authority
819              
820             # 'cpan:AWNCORP'
821              
822             =back
823              
824             =cut
825              
826             =head2 base
827              
828             base() : Str
829              
830             The base method returns the last segment of the package namespace parts.
831              
832             =over 4
833              
834             =item base example #1
835              
836             # given: synopsis
837              
838             $space->base
839              
840             # Bar
841              
842             =back
843              
844             =cut
845              
846             =head2 bless
847              
848             bless(Any $arg1 = {}) : Object
849              
850             The bless method blesses the given value into the package namespace and returns
851             an object. If no value is given, an empty hashref is used.
852              
853             =over 4
854              
855             =item bless example #1
856              
857             # given: synopsis
858              
859             package Foo::Bar;
860              
861             sub import;
862              
863             package main;
864              
865             $space->bless
866              
867             # bless({}, 'Foo::Bar')
868              
869             =back
870              
871             =over 4
872              
873             =item bless example #2
874              
875             # given: synopsis
876              
877             package Foo::Bar;
878              
879             sub import;
880              
881             package main;
882              
883             $space->bless({okay => 1})
884              
885             # bless({okay => 1}, 'Foo::Bar')
886              
887             =back
888              
889             =cut
890              
891             =head2 build
892              
893             build(Any @args) : Object
894              
895             The build method attempts to call C<new> on the package namespace and if successful returns the resulting object.
896              
897             =over 4
898              
899             =item build example #1
900              
901             package Foo::Bar::Baz;
902              
903             sub new {
904             bless {}, $_[0]
905             }
906              
907             package main;
908              
909             use Data::Object::Space;
910              
911             my $space = Data::Object::Space->new('foo/bar/baz');
912              
913             $space->build
914              
915             # bless({}, 'Foo::Bar::Baz')
916              
917             =back
918              
919             =over 4
920              
921             =item build example #2
922              
923             package Foo::Bar::Bax;
924              
925             sub new {
926             bless $_[1], $_[0]
927             }
928              
929             package main;
930              
931             use Data::Object::Space;
932              
933             my $space = Data::Object::Space->new('foo/bar/bax');
934              
935             $space->build({okay => 1})
936              
937             # bless({okay => 1}, 'Foo::Bar::Bax')
938              
939             =back
940              
941             =cut
942              
943             =head2 call
944              
945             call(Any @args) : Any
946              
947             The call method attempts to call the given subroutine on the package namespace
948             and if successful returns the resulting value.
949              
950             =over 4
951              
952             =item call example #1
953              
954             # given: synopsis
955              
956             package Foo;
957              
958             sub import;
959              
960             sub start {
961             'started'
962             }
963              
964             package main;
965              
966             use Data::Object::Space;
967              
968             $space = Data::Object::Space->new('foo');
969              
970             $space->call('start')
971              
972             # started
973              
974             =back
975              
976             =over 4
977              
978             =item call example #2
979              
980             # given: synopsis
981              
982             package Zoo;
983              
984             sub import;
985              
986             sub AUTOLOAD {
987             bless {};
988             }
989              
990             sub DESTROY {
991             ; # noop
992             }
993              
994             package main;
995              
996             use Data::Object::Space;
997              
998             $space = Data::Object::Space->new('zoo');
999              
1000             $space->call('start')
1001              
1002             # bless({}, 'Zoo')
1003              
1004             =back
1005              
1006             =cut
1007              
1008             =head2 chain
1009              
1010             chain(Str | Tuple[Str, Any] @steps) : Any
1011              
1012             The chain method chains one or more method calls and returns the result.
1013              
1014             =over 4
1015              
1016             =item chain example #1
1017              
1018             package Chu::Chu0;
1019              
1020             sub import;
1021              
1022             package main;
1023              
1024             my $space = Data::Object::Space->new('Chu::Chu0');
1025              
1026             $space->chain('bless');
1027              
1028             =back
1029              
1030             =over 4
1031              
1032             =item chain example #2
1033              
1034             package Chu::Chu1;
1035              
1036             sub import;
1037              
1038             sub new {
1039             bless pop;
1040             }
1041              
1042             sub frame {
1043             [@_]
1044             }
1045              
1046             package main;
1047              
1048             my $space = Data::Object::Space->new('Chu::Chu1');
1049              
1050             $space->chain(['bless', {1..4}], 'frame');
1051              
1052             # [ bless( { '1' => 2, '3' => 4 }, 'Chu::Chu1' ) ]
1053              
1054             =back
1055              
1056             =over 4
1057              
1058             =item chain example #3
1059              
1060             package Chu::Chu2;
1061              
1062             sub import;
1063              
1064             sub new {
1065             bless pop;
1066             }
1067              
1068             sub frame {
1069             [@_]
1070             }
1071              
1072             package main;
1073              
1074             my $space = Data::Object::Space->new('Chu::Chu2');
1075              
1076             $space->chain('bless', ['frame', {1..4}]);
1077              
1078             # [ bless( {}, 'Chu::Chu2' ), { '1' => 2, '3' => 4 } ]
1079              
1080             =back
1081              
1082             =cut
1083              
1084             =head2 child
1085              
1086             child(Str $arg1) : Object
1087              
1088             The child method returns a new L<Data::Object::Space> object for the child
1089             package namespace.
1090              
1091             =over 4
1092              
1093             =item child example #1
1094              
1095             # given: synopsis
1096              
1097             $space->child('baz');
1098              
1099             # $space->package;
1100              
1101             # Foo::Bar::Baz
1102              
1103             =back
1104              
1105             =cut
1106              
1107             =head2 children
1108              
1109             children() : ArrayRef[Object]
1110              
1111             The children method searches C<%INC> and C<@INC> and retuns a list of
1112             L<Data::Object::Space> objects for each child namespace found (one level deep).
1113              
1114             =over 4
1115              
1116             =item children example #1
1117              
1118             package main;
1119              
1120             use Data::Object::Space;
1121              
1122             my $space = Data::Object::Space->new('c_p_a_n');
1123              
1124             $space->children
1125              
1126             # [
1127             # 'CPAN/Author',
1128             # 'CPAN/Bundle',
1129             # 'CPAN/CacheMgr',
1130             # ...
1131             # ]
1132              
1133             =back
1134              
1135             =cut
1136              
1137             =head2 cop
1138              
1139             cop(Any @args) : CodeRef
1140              
1141             The cop method attempts to curry the given subroutine on the package namespace
1142             and if successful returns a closure.
1143              
1144             =over 4
1145              
1146             =item cop example #1
1147              
1148             # given: synopsis
1149              
1150             package Foo::Bar;
1151              
1152             sub import;
1153              
1154             sub handler {
1155             [@_]
1156             }
1157              
1158             package main;
1159              
1160             use Data::Object::Space;
1161              
1162             $space = Data::Object::Space->new('foo/bar');
1163              
1164             $space->cop('handler', $space->bless)
1165              
1166             # sub { Foo::Bar::handler(..., @_) }
1167              
1168             =back
1169              
1170             =cut
1171              
1172             =head2 data
1173              
1174             data() : Str
1175              
1176             The data method attempts to read and return any content stored in the C<DATA>
1177             section of the package namespace.
1178              
1179             =over 4
1180              
1181             =item data example #1
1182              
1183             package main;
1184              
1185             use Data::Object::Space;
1186              
1187             my $space = Data::Object::Space->new('foo');
1188              
1189             $space->data; # ''
1190              
1191             =back
1192              
1193             =cut
1194              
1195             =head2 destroy
1196              
1197             destroy() : Object
1198              
1199             The destroy method attempts to wipe out a namespace and also remove it and its
1200             children from C<%INC>. B<NOTE:> This can cause catastrophic failures if used
1201             incorrectly.
1202              
1203             =over 4
1204              
1205             =item destroy example #1
1206              
1207             package main;
1208              
1209             use Data::Object::Space;
1210              
1211             my $space = Data::Object::Space->new('data/dumper');
1212              
1213             $space->load; # Data/Dumper
1214              
1215             $space->destroy;
1216              
1217             =back
1218              
1219             =cut
1220              
1221             =head2 eval
1222              
1223             eval(Str @args) : Any
1224              
1225             The eval method takes a list of strings and evaluates them under the namespace
1226             represented by the instance.
1227              
1228             =over 4
1229              
1230             =item eval example #1
1231              
1232             package main;
1233              
1234             use Data::Object::Space;
1235              
1236             my $space = Data::Object::Space->new('foo');
1237              
1238             $space->eval('our $VERSION = 0.01');
1239              
1240             =back
1241              
1242             =cut
1243              
1244             =head2 functions
1245              
1246             functions() : ArrayRef
1247              
1248             The functions method searches the package namespace for functions and returns
1249             their names.
1250              
1251             =over 4
1252              
1253             =item functions example #1
1254              
1255             package Foo::Functions;
1256              
1257             use routines;
1258              
1259             fun start() {
1260             1
1261             }
1262              
1263             package main;
1264              
1265             use Data::Object::Space;
1266              
1267             my $space = Data::Object::Space->new('foo/functions');
1268              
1269             $space->functions
1270              
1271             # ['start']
1272              
1273             =back
1274              
1275             =cut
1276              
1277             =head2 hash
1278              
1279             hash(Str $arg1) : HashRef
1280              
1281             The hash method returns the value for the given package hash variable name.
1282              
1283             =over 4
1284              
1285             =item hash example #1
1286              
1287             # given: synopsis
1288              
1289             package Foo::Bar;
1290              
1291             our %settings = (
1292             active => 1
1293             );
1294              
1295             package main;
1296              
1297             $space->hash('settings')
1298              
1299             # {active => 1}
1300              
1301             =back
1302              
1303             =cut
1304              
1305             =head2 hashes
1306              
1307             hashes() : ArrayRef
1308              
1309             The hashes method searches the package namespace for hashes and returns their
1310             names.
1311              
1312             =over 4
1313              
1314             =item hashes example #1
1315              
1316             # given: synopsis
1317              
1318             package Foo::Bar;
1319              
1320             our %defaults = (
1321             active => 0
1322             );
1323              
1324             our %settings = (
1325             active => 1
1326             );
1327              
1328             package main;
1329              
1330             $space->hashes
1331              
1332             # ['defaults', 'settings']
1333              
1334             =back
1335              
1336             =cut
1337              
1338             =head2 id
1339              
1340             id() : Str
1341              
1342             The id method returns the fully-qualified package name as a label.
1343              
1344             =over 4
1345              
1346             =item id example #1
1347              
1348             # given: synopsis
1349              
1350             $space->id
1351              
1352             # Foo_Bar
1353              
1354             =back
1355              
1356             =cut
1357              
1358             =head2 included
1359              
1360             included() : Str
1361              
1362             The included method returns the path of the namespace if it exists in C<%INC>.
1363              
1364             =over 4
1365              
1366             =item included example #1
1367              
1368             package main;
1369              
1370             my $space = Data::Object::Space->new('Data/Object/Space');
1371              
1372             $space->included;
1373              
1374             # lib/Data/Object/Space.pm
1375              
1376             =back
1377              
1378             =cut
1379              
1380             =head2 inherits
1381              
1382             inherits() : ArrayRef
1383              
1384             The inherits method returns the list of superclasses the target package is
1385             derived from.
1386              
1387             =over 4
1388              
1389             =item inherits example #1
1390              
1391             package Bar;
1392              
1393             package main;
1394              
1395             my $space = Data::Object::Space->new('bar');
1396              
1397             $space->inherits
1398              
1399             # []
1400              
1401             =back
1402              
1403             =over 4
1404              
1405             =item inherits example #2
1406              
1407             package Foo;
1408              
1409             package Bar;
1410              
1411             use base 'Foo';
1412              
1413             package main;
1414              
1415             my $space = Data::Object::Space->new('bar');
1416              
1417             $space->inherits
1418              
1419             # ['Foo']
1420              
1421             =back
1422              
1423             =cut
1424              
1425             =head2 init
1426              
1427             init() : Str
1428              
1429             The init method ensures that the package namespace is loaded and, whether
1430             created in-memory or on-disk, is flagged as being loaded and loadable.
1431              
1432             =over 4
1433              
1434             =item init example #1
1435              
1436             package main;
1437              
1438             use Data::Object::Space;
1439              
1440             my $space = Data::Object::Space->new('kit');
1441              
1442             $space->init
1443              
1444             # Kit
1445              
1446             =back
1447              
1448             =cut
1449              
1450             =head2 inject
1451              
1452             inject(Str $name, Maybe[CodeRef] $coderef) : Any
1453              
1454             The inject method monkey-patches the package namespace, installing a named
1455             subroutine into the package which can then be called normally, returning the
1456             fully-qualified subroutine name.
1457              
1458             =over 4
1459              
1460             =item inject example #1
1461              
1462             package main;
1463              
1464             use Data::Object::Space;
1465              
1466             my $space = Data::Object::Space->new('kit');
1467              
1468             $space->inject('build', sub { 'finished' });
1469              
1470             # *Kit::build
1471              
1472             =back
1473              
1474             =cut
1475              
1476             =head2 load
1477              
1478             load() : Str
1479              
1480             The load method checks whether the package namespace is already loaded and if
1481             not attempts to load the package. If the package is not loaded and is not
1482             loadable, this method will throw an exception using confess. If the package is
1483             loadable, this method returns truthy with the package name. As a workaround for
1484             packages that only exist in-memory, if the package contains a C<new>, C<with>,
1485             C<meta>, or C<import> routine it will be recognized as having been loaded.
1486              
1487             =over 4
1488              
1489             =item load example #1
1490              
1491             package main;
1492              
1493             use Data::Object::Space;
1494              
1495             my $space = Data::Object::Space->new('c_p_a_n');
1496              
1497             $space->load
1498              
1499             # CPAN
1500              
1501             =back
1502              
1503             =cut
1504              
1505             =head2 loaded
1506              
1507             loaded() : Int
1508              
1509             The loaded method checks whether the package namespace is already loaded
1510             returns truthy or falsy.
1511              
1512             =over 4
1513              
1514             =item loaded example #1
1515              
1516             package main;
1517              
1518             use Data::Object::Space;
1519              
1520             my $space = Data::Object::Space->new('data/dumper');
1521              
1522             $space->loaded;
1523              
1524             # 0
1525              
1526             =back
1527              
1528             =over 4
1529              
1530             =item loaded example #2
1531              
1532             package main;
1533              
1534             use Data::Object::Space;
1535              
1536             my $space = Data::Object::Space->new('data/dumper');
1537              
1538             $space->load;
1539              
1540             $space->loaded;
1541              
1542             # 1
1543              
1544             =back
1545              
1546             =cut
1547              
1548             =head2 locate
1549              
1550             locate() : Str
1551              
1552             The locate method checks whether the package namespace is available in
1553             C<@INC>, i.e. on disk. This method returns the file if found or an empty
1554             string.
1555              
1556             =over 4
1557              
1558             =item locate example #1
1559              
1560             package main;
1561              
1562             use Data::Object::Space;
1563              
1564             my $space = Data::Object::Space->new('brianne_spinka');
1565              
1566             $space->locate;
1567              
1568             # ''
1569              
1570             =back
1571              
1572             =over 4
1573              
1574             =item locate example #2
1575              
1576             package main;
1577              
1578             use Data::Object::Space;
1579              
1580             my $space = Data::Object::Space->new('data/dumper');
1581              
1582             $space->locate;
1583              
1584             # /path/to/Data/Dumper.pm
1585              
1586             =back
1587              
1588             =cut
1589              
1590             =head2 methods
1591              
1592             methods() : ArrayRef
1593              
1594             The methods method searches the package namespace for methods and returns their
1595             names.
1596              
1597             =over 4
1598              
1599             =item methods example #1
1600              
1601             package Foo::Methods;
1602              
1603             use routines;
1604              
1605             method start() {
1606             1
1607             }
1608              
1609             package main;
1610              
1611             use Data::Object::Space;
1612              
1613             my $space = Data::Object::Space->new('foo/methods');
1614              
1615             $space->methods
1616              
1617             # ['start']
1618              
1619             =back
1620              
1621             =cut
1622              
1623             =head2 name
1624              
1625             name() : Str
1626              
1627             The name method returns the fully-qualified package name.
1628              
1629             =over 4
1630              
1631             =item name example #1
1632              
1633             # given: synopsis
1634              
1635             $space->name
1636              
1637             # Foo::Bar
1638              
1639             =back
1640              
1641             =cut
1642              
1643             =head2 parent
1644              
1645             parent() : Object
1646              
1647             The parent method returns a new L<Data::Object::Space> object for the parent
1648             package namespace.
1649              
1650             =over 4
1651              
1652             =item parent example #1
1653              
1654             # given: synopsis
1655              
1656             $space->parent;
1657              
1658             # $space->package;
1659              
1660             # Foo
1661              
1662             =back
1663              
1664             =cut
1665              
1666             =head2 parse
1667              
1668             parse() : ArrayRef
1669              
1670             The parse method parses the string argument and returns an arrayref of package
1671             namespace segments (parts).
1672              
1673             =over 4
1674              
1675             =item parse example #1
1676              
1677             my $space = Data::Object::Space->new('Foo::Bar');
1678              
1679             $space->parse;
1680              
1681             # ['Foo', 'Bar']
1682              
1683             =back
1684              
1685             =over 4
1686              
1687             =item parse example #2
1688              
1689             my $space = Data::Object::Space->new('Foo/Bar');
1690              
1691             $space->parse;
1692              
1693             # ['Foo', 'Bar']
1694              
1695             =back
1696              
1697             =over 4
1698              
1699             =item parse example #3
1700              
1701             my $space = Data::Object::Space->new('Foo\Bar');
1702              
1703             $space->parse;
1704              
1705             # ['Foo', 'Bar']
1706              
1707             =back
1708              
1709             =over 4
1710              
1711             =item parse example #4
1712              
1713             my $space = Data::Object::Space->new('foo-bar');
1714              
1715             $space->parse;
1716              
1717             # ['FooBar']
1718              
1719             =back
1720              
1721             =over 4
1722              
1723             =item parse example #5
1724              
1725             my $space = Data::Object::Space->new('foo_bar');
1726              
1727             $space->parse;
1728              
1729             # ['FooBar']
1730              
1731             =back
1732              
1733             =cut
1734              
1735             =head2 parts
1736              
1737             parts() : ArrayRef
1738              
1739             The parts method returns an arrayref of package namespace segments (parts).
1740              
1741             =over 4
1742              
1743             =item parts example #1
1744              
1745             my $space = Data::Object::Space->new('foo');
1746              
1747             $space->parts;
1748              
1749             # ['Foo']
1750              
1751             =back
1752              
1753             =over 4
1754              
1755             =item parts example #2
1756              
1757             my $space = Data::Object::Space->new('foo/bar');
1758              
1759             $space->parts;
1760              
1761             # ['Foo', 'Bar']
1762              
1763             =back
1764              
1765             =over 4
1766              
1767             =item parts example #3
1768              
1769             my $space = Data::Object::Space->new('foo_bar');
1770              
1771             $space->parts;
1772              
1773             # ['FooBar']
1774              
1775             =back
1776              
1777             =cut
1778              
1779             =head2 prepend
1780              
1781             prepend(Str @args) : Object
1782              
1783             The prepend method modifies the object by prepending to the package namespace
1784             parts.
1785              
1786             =over 4
1787              
1788             =item prepend example #1
1789              
1790             # given: synopsis
1791              
1792             $space->prepend('etc');
1793              
1794             # 'Etc/Foo/Bar'
1795              
1796             =back
1797              
1798             =over 4
1799              
1800             =item prepend example #2
1801              
1802             # given: synopsis
1803              
1804             $space->prepend('etc', 'tmp');
1805              
1806             # 'Etc/Tmp/Foo/Bar'
1807              
1808             =back
1809              
1810             =cut
1811              
1812             =head2 rebase
1813              
1814             rebase(Str @args) : Object
1815              
1816             The rebase method returns an object by prepending the package namespace
1817             specified to the base of the current object's namespace.
1818              
1819             =over 4
1820              
1821             =item rebase example #1
1822              
1823             # given: synopsis
1824              
1825             $space->rebase('zoo');
1826              
1827             # Zoo/Bar
1828              
1829             =back
1830              
1831             =cut
1832              
1833             =head2 reload
1834              
1835             reload() : Str
1836              
1837             The reload method attempts to delete and reload the package namespace using the
1838             L</load> method. B<Note:> Reloading is additive and will overwrite existing
1839             symbols but does not remove symbols.
1840              
1841             =over 4
1842              
1843             =item reload example #1
1844              
1845             package main;
1846              
1847             use Data::Object::Space;
1848              
1849             # Foo::Gen is generate with $VERSION as 0.01
1850              
1851             my $space = Data::Object::Space->new('foo/gen');
1852              
1853             $space->reload;
1854              
1855             # Foo::Gen
1856             # Foo::Gen->VERSION is 0.01
1857              
1858             =back
1859              
1860             =over 4
1861              
1862             =item reload example #2
1863              
1864             package main;
1865              
1866             use Data::Object::Space;
1867              
1868             # Foo::Gen is regenerated with $VERSION as 0.02
1869              
1870             my $space = Data::Object::Space->new('foo/gen');
1871              
1872             $space->reload;
1873              
1874             # Foo::Gen
1875             # Foo::Gen->VERSION is 0.02
1876              
1877             =back
1878              
1879             =cut
1880              
1881             =head2 require
1882              
1883             require(Str $target) : Any
1884              
1885             The require method executes a C<require> statement within the package namespace
1886             specified.
1887              
1888             =over 4
1889              
1890             =item require example #1
1891              
1892             # given: synopsis
1893              
1894             $space->require('Moo');
1895              
1896             # 1
1897              
1898             =back
1899              
1900             =cut
1901              
1902             =head2 root
1903              
1904             root() : Str
1905              
1906             The root method returns the root package namespace segments (parts). Sometimes
1907             separating the C<root> from the C<parts> helps identify how subsequent child
1908             objects were derived.
1909              
1910             =over 4
1911              
1912             =item root example #1
1913              
1914             # given: synopsis
1915              
1916             $space->root;
1917              
1918             # Foo
1919              
1920             =back
1921              
1922             =cut
1923              
1924             =head2 routine
1925              
1926             routine(Str $arg1) : CodeRef
1927              
1928             The routine method returns the subroutine reference for the given subroutine
1929             name.
1930              
1931             =over 4
1932              
1933             =item routine example #1
1934              
1935             package Foo;
1936              
1937             sub cont {
1938             [@_]
1939             }
1940              
1941             sub abort {
1942             [@_]
1943             }
1944              
1945             package main;
1946              
1947             use Data::Object::Space;
1948              
1949             my $space = Data::Object::Space->new('foo');
1950              
1951             $space->routine('cont')
1952              
1953             # sub { ... }
1954              
1955             =back
1956              
1957             =cut
1958              
1959             =head2 routines
1960              
1961             routines() : ArrayRef
1962              
1963             The routines method searches the package namespace for routines and returns
1964             their names.
1965              
1966             =over 4
1967              
1968             =item routines example #1
1969              
1970             package Foo::Routines;
1971              
1972             sub start {
1973             1
1974             }
1975              
1976             sub abort {
1977             1
1978             }
1979              
1980             package main;
1981              
1982             use Data::Object::Space;
1983              
1984             my $space = Data::Object::Space->new('foo/routines');
1985              
1986             $space->routines
1987              
1988             # ['start', 'abort']
1989              
1990             =back
1991              
1992             =cut
1993              
1994             =head2 scalar
1995              
1996             scalar(Str $arg1) : Any
1997              
1998             The scalar method returns the value for the given package scalar variable name.
1999              
2000             =over 4
2001              
2002             =item scalar example #1
2003              
2004             # given: synopsis
2005              
2006             package Foo::Bar;
2007              
2008             our $root = '/path/to/file';
2009              
2010             package main;
2011              
2012             $space->scalar('root')
2013              
2014             # /path/to/file
2015              
2016             =back
2017              
2018             =cut
2019              
2020             =head2 scalars
2021              
2022             scalars() : ArrayRef
2023              
2024             The scalars method searches the package namespace for scalars and returns their
2025             names.
2026              
2027             =over 4
2028              
2029             =item scalars example #1
2030              
2031             # given: synopsis
2032              
2033             package Foo::Bar;
2034              
2035             our $root = 'root';
2036             our $base = 'path/to';
2037             our $file = 'file';
2038              
2039             package main;
2040              
2041             $space->scalars
2042              
2043             # ['root', 'base', 'file']
2044              
2045             =back
2046              
2047             =cut
2048              
2049             =head2 sibling
2050              
2051             sibling(Str $arg1) : Object
2052              
2053             The sibling method returns a new L<Data::Object::Space> object for the sibling
2054             package namespace.
2055              
2056             =over 4
2057              
2058             =item sibling example #1
2059              
2060             # given: synopsis
2061              
2062             $space->sibling('baz')
2063              
2064             # Foo::Baz
2065              
2066             =back
2067              
2068             =cut
2069              
2070             =head2 siblings
2071              
2072             siblings() : ArrayRef[Object]
2073              
2074             The siblings method searches C<%INC> and C<@INC> and retuns a list of
2075             L<Data::Object::Space> objects for each sibling namespace found (one level
2076             deep).
2077              
2078             =over 4
2079              
2080             =item siblings example #1
2081              
2082             package main;
2083              
2084             use Data::Object::Space;
2085              
2086             my $space = Data::Object::Space->new('encode/m_i_m_e');
2087              
2088             $space->siblings
2089              
2090             # [
2091             # 'Encode/Alias',
2092             # 'Encode/Config'
2093             # ...
2094             # ]
2095              
2096             =back
2097              
2098             =cut
2099              
2100             =head2 tryload
2101              
2102             tryload() : Bool
2103              
2104             The tryload method attempt to C<load> the represented package using the
2105             L</load> method and returns truthy/falsy based on whether the package was
2106             loaded.
2107              
2108             =over 4
2109              
2110             =item tryload example #1
2111              
2112             package main;
2113              
2114             use Data::Object::Space;
2115              
2116             my $space = Data::Object::Space->new('c_p_a_n');
2117              
2118             $space->tryload
2119              
2120             # 1
2121              
2122             =back
2123              
2124             =over 4
2125              
2126             =item tryload example #2
2127              
2128             package main;
2129              
2130             use Data::Object::Space;
2131              
2132             my $space = Data::Object::Space->new('brianne_spinka');
2133              
2134             $space->tryload
2135              
2136             # 0
2137              
2138             =back
2139              
2140             =cut
2141              
2142             =head2 use
2143              
2144             use(Str | Tuple[Str, Str] $target, Any @params) : Object
2145              
2146             The use method executes a C<use> statement within the package namespace
2147             specified.
2148              
2149             =over 4
2150              
2151             =item use example #1
2152              
2153             package main;
2154              
2155             use Data::Object::Space;
2156              
2157             my $space = Data::Object::Space->new('foo/goo');
2158              
2159             $space->use('Moo');
2160              
2161             # $self
2162              
2163             =back
2164              
2165             =over 4
2166              
2167             =item use example #2
2168              
2169             package main;
2170              
2171             use Data::Object::Space;
2172              
2173             my $space = Data::Object::Space->new('foo/hoo');
2174              
2175             $space->use('Moo', 'has');
2176              
2177             # $self
2178              
2179             =back
2180              
2181             =over 4
2182              
2183             =item use example #3
2184              
2185             package main;
2186              
2187             use Data::Object::Space;
2188              
2189             my $space = Data::Object::Space->new('foo/ioo');
2190              
2191             $space->use(['Moo', 9.99], 'has');
2192              
2193             # $self
2194              
2195             =back
2196              
2197             =cut
2198              
2199             =head2 used
2200              
2201             used() : Str
2202              
2203             The used method searches C<%INC> for the package namespace and if found returns
2204             the filepath and complete filepath for the loaded package, otherwise returns
2205             falsy with an empty string.
2206              
2207             =over 4
2208              
2209             =item used example #1
2210              
2211             package main;
2212              
2213             use Data::Object::Space;
2214              
2215             my $space = Data::Object::Space->new('foo/xyz');
2216              
2217             $space->used
2218              
2219             # ''
2220              
2221             =back
2222              
2223             =over 4
2224              
2225             =item used example #2
2226              
2227             package main;
2228              
2229             use Data::Object::Space;
2230              
2231             my $space = Data::Object::Space->new('c_p_a_n');
2232              
2233             $space->load;
2234             $space->used
2235              
2236             # 'CPAN'
2237              
2238             =back
2239              
2240             =over 4
2241              
2242             =item used example #3
2243              
2244             package Foo::Bar;
2245              
2246             sub import;
2247              
2248             package main;
2249              
2250             use Data::Object::Space;
2251              
2252             my $space = Data::Object::Space->new('foo/bar');
2253              
2254             $space->used
2255              
2256             # 'Foo/Bar'
2257              
2258             =back
2259              
2260             =cut
2261              
2262             =head2 variables
2263              
2264             variables() : ArrayRef[Tuple[Str, ArrayRef]]
2265              
2266             The variables method searches the package namespace for variables and returns
2267             their names.
2268              
2269             =over 4
2270              
2271             =item variables example #1
2272              
2273             package Etc;
2274              
2275             our $init = 0;
2276             our $func = 1;
2277              
2278             our @does = (1..4);
2279             our %sets = (1..4);
2280              
2281             package main;
2282              
2283             use Data::Object::Space;
2284              
2285             my $space = Data::Object::Space->new('etc');
2286              
2287             $space->variables
2288              
2289             # [
2290             # ['arrays', ['does']],
2291             # ['hashes', ['sets']],
2292             # ['scalars', ['func', 'init']],
2293             # ]
2294              
2295             =back
2296              
2297             =cut
2298              
2299             =head2 version
2300              
2301             version() : Maybe[Str]
2302              
2303             The version method returns the C<VERSION> declared on the target package, if
2304             any.
2305              
2306             =over 4
2307              
2308             =item version example #1
2309              
2310             package Foo::Boo;
2311              
2312             package main;
2313              
2314             use Data::Object::Space;
2315              
2316             my $space = Data::Object::Space->new('foo/boo');
2317              
2318             $space->version
2319              
2320             # undef
2321              
2322             =back
2323              
2324             =over 4
2325              
2326             =item version example #2
2327              
2328             package Foo::Boo;
2329              
2330             our $VERSION = 0.01;
2331              
2332             package main;
2333              
2334             use Data::Object::Space;
2335              
2336             my $space = Data::Object::Space->new('foo/boo');
2337              
2338             $space->version
2339              
2340             # '0.01'
2341              
2342             =back
2343              
2344             =cut
2345              
2346             =head1 AUTHOR
2347              
2348             Al Newkirk, C<awncorp@cpan.org>
2349              
2350             =head1 LICENSE
2351              
2352             Copyright (C) 2011-2019, Al Newkirk, et al.
2353              
2354             This is free software; you can redistribute it and/or modify it under the terms
2355             of the The Apache License, Version 2.0, as elucidated in the L<"license
2356             file"|https://github.com/iamalnewkirk/data-object-space/blob/master/LICENSE>.
2357              
2358             =head1 PROJECT
2359              
2360             L<Wiki|https://github.com/iamalnewkirk/data-object-space/wiki>
2361              
2362             L<Project|https://github.com/iamalnewkirk/data-object-space>
2363              
2364             L<Initiatives|https://github.com/iamalnewkirk/data-object-space/projects>
2365              
2366             L<Milestones|https://github.com/iamalnewkirk/data-object-space/milestones>
2367              
2368             L<Contributing|https://github.com/iamalnewkirk/data-object-space/blob/master/CONTRIBUTE.md>
2369              
2370             L<Issues|https://github.com/iamalnewkirk/data-object-space/issues>
2371              
2372             =cut