File Coverage

blib/lib/Data/Object/Space.pm
Criterion Covered Total %
statement 424 451 94.0
branch 56 78 71.7
condition 11 24 45.8
subroutine 75 79 94.9
pod 48 49 97.9
total 614 681 90.1


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