| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package new; | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | our $VERSION = '0.000001'; # 0.0.1 | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  | $VERSION = eval $VERSION; | 
| 6 |  |  |  |  |  |  |  | 
| 7 | 1 |  |  | 1 |  | 56010 | use strict; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 23 |  | 
| 8 | 1 |  |  | 1 |  | 4 | use warnings; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 114 |  | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | sub import { | 
| 11 | 5 |  |  | 5 |  | 2409 | my ($me, $class, @args) = @_; | 
| 12 | 5 | 100 |  |  |  | 1144 | return unless $class; | 
| 13 | 4 |  |  |  |  | 7 | my $targ = caller; | 
| 14 | 4 |  |  |  |  | 295 | require join('/', split '::', $class).'.pm'; | 
| 15 | 4 | 100 | 100 |  |  | 157 | my ($name) = @args && $args[0] =~ /^\$/ ? map /^\$(.*)/, shift @args : 'O'; | 
| 16 | 4 |  |  |  |  | 14 | my $obj = $class->new(@args); | 
| 17 | 1 |  |  | 1 |  | 6 | no strict 'refs'; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 63 |  | 
| 18 | 4 |  |  |  |  | 18 | ${"${targ}::${name}"} = $obj; | 
|  | 4 |  |  |  |  | 16 |  | 
| 19 |  |  |  |  |  |  | } | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | 1; | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  | =head1 NAME | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  | new - Object instantiation sugar for one-liners | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 28 |  |  |  |  |  |  |  | 
| 29 |  |  |  |  |  |  | Simplest possible usage: | 
| 30 |  |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  | perl -Mnew=HTTP::Tiny -E \ | 
| 32 |  |  |  |  |  |  | 'say $O->get("http://trout.me.uk/X11/vimrc")->{content}' | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | With arguments: | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | perl -Mnew=HTTP::Tiny,max_redirects,3 -E \ | 
| 37 |  |  |  |  |  |  | 'say $O->get("http://trout.me.uk/X11/vimrc")->{content}' | 
| 38 |  |  |  |  |  |  |  | 
| 39 |  |  |  |  |  |  | With custom object name: | 
| 40 |  |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  | perl -Mnew=HTTP::Tiny,\$H -E \ | 
| 42 |  |  |  |  |  |  | 'say $H->get("http://trout.me.uk/X11/vimrc")->{content}' | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | With both: | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | perl -Mnew=HTTP::Tiny,\$H,max_redirects,3 -E \ | 
| 47 |  |  |  |  |  |  | 'say $H->get("http://trout.me.uk/X11/vimrc")->{content}' | 
| 48 |  |  |  |  |  |  |  | 
| 49 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 50 |  |  |  |  |  |  |  | 
| 51 |  |  |  |  |  |  | =head2 import | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | new->import($class, @args) | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | First we C the file for C<$class>, then call | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | $class->new(@args) | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | then install the resulting object in C<$O> in the calling package. | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | If the first argument to C after C<$class> begins with C<$>, this | 
| 62 |  |  |  |  |  |  | is treated as the name to install the object as, so | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | new->import($class, '$Obj', @args); | 
| 65 |  |  |  |  |  |  |  | 
| 66 |  |  |  |  |  |  | will create a variable C<$Obj> in the calling package instead of C<$O>. | 
| 67 |  |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  | =head1 AUTHOR | 
| 69 |  |  |  |  |  |  |  | 
| 70 |  |  |  |  |  |  | mst - Matt S. Trout (cpan:MSTROUT) | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | =head1 CONTRIBUTORS | 
| 73 |  |  |  |  |  |  |  | 
| 74 |  |  |  |  |  |  | None yet - maybe this software is perfect! (ahahahahahahahahaha) | 
| 75 |  |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  | =head1 COPYRIGHT | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | Copyright (c) 2020 the new L and L | 
| 79 |  |  |  |  |  |  | as listed above. | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | =head1 LICENSE | 
| 82 |  |  |  |  |  |  |  | 
| 83 |  |  |  |  |  |  | This library is free software and may be distributed under the same terms | 
| 84 |  |  |  |  |  |  | as perl itself. |