blib/lib/new.pm

filter: Statementstmt 100% 20 / 20 Branchbran 100% 4 / 4 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 100% 33 / 33 SCAR 13.9
CC
4
Cov
100%
import
4.0
BEGIN
1.0
BEGIN
1.0
CRAP 4.0
↑ Summary
1 package new;
2  
3 1 our $VERSION = '0.000001'; # 0.0.1
4  
5 1 $VERSION = eval $VERSION;
6  
7 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 sub import {
11 5 ▶ my ($me, $class, @args) = @_;
Subroutine import: called CC=4 SCAR=13.9
12 5 ▶ return unless $class;
Branch: 1 branch
BranchTrueFalseTotal
unless $class 1 4 5
13 4 my $targ = caller;
14 4 require join('/', split '::', $class).'.pm';
15 4 ▶ my ($name) = @args && $args[0] =~ /^\$/ ? map /^\$(.*)/, shift @args : 'O';
Branch: 1 branch
BranchTrueFalseTotal
@args && $args[0] =~ /^\$/ ? : 2 2 4
Condition100%3/3
@args and $args[0] =~ /^\$/
!ll&&!rl&&r
112
MC/DC100%2/2
@args and $args[0] =~ /^\$/
@args $args[0] =~ /^\$/
Truth table100%3/3
A and B
A= @argsB= $args[0] =~ /^\$/
ABresult
0X0
100
111
16 4 my $obj = $class->new(@args);
17 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
18 4 ${"${targ}::${name}"} = $obj;
19 }
20  
21 1 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<require> 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<import> 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) <mst@shadowcat.co.uk>
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</AUTHOR> and L</CONTRIBUTORS>
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.
↑ Summary