blib/lib/Syntax/Feature/Qwa.pm

filter: Statementstmt 100% 58 / 58 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 15 / 15 Podpod 0.0% 0 / 1 totaltotal 98.6% 73 / 74 CC 2 SCAR 1.2
CC
2
Cov
100%
install
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
↑ Summary
1 package Syntax::Feature::Qwa;
2  
3 4 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 $Syntax::Feature::Qwa::AUTHORITY = 'cpan:TOBYINK';
8 4 $Syntax::Feature::Qwa::VERSION = '0.002';
9 }
10  
11 4 ▶use Devel::Declare 0.006007 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use Devel::Declare::Context::Simple 0 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 ▶use B::Hooks::EndOfScope 0.09;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 ▶use Sub::Install 0.925 qw( install_sub );
Subroutine BEGIN: called CC=1 SCAR=0.0
15 4 ▶use namespace::clean 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
16
17 4 my @NewOps = qw(qwa qwh qwk);
18 4 my %QuoteOp = (
19 qwa => q{ [%s] },
20 qwh => q{ +{%s} },
21 qwk => q{ do { my $i = 0; +{ map { $_=>++$i } %s } } },
22 );
23  
24 sub import
25 4 ▶{
Subroutine import: called CC=1 SCAR=0.0
26 4 my ($class) = @_;
27 4 my $caller = caller(0);
28 4 @_ = ($class, 'into', $caller);
29 4 goto \&install;
30 }
31  
32 sub install
33 4 ▶{
Subroutine install: called CC=2 SCAR=6.9
Pod undocumented
34 4 my ($class, %args) = @_;
35
36 4 my $target = $args{into};
37 Devel::Declare->setup_for($target => {
38 map {
39 4 my $name = $_;
40 ($name => {
41 3 ▶ const => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
42 3 my $ctx = Devel::Declare::Context::Simple->new;
43 3 $ctx->init(@_);
44 3 return $class->_transform($name, $ctx);
45 },
46 })
47 12 } @NewOps
48 });
49 4 for my $name (@NewOps) {
50 12 install_sub {
51 into => $target,
52 as => $name,
53 code => $class->_run_callback($name),
54 }
55 }
56 4 ▶ on_scope_end {
Subroutine __ANON__: called CC=1 SCAR=0.0
57 4 namespace::clean->clean_subroutines($target, @NewOps);
58 4 };
59 4 return 1;
60 }
61  
62 3 ▶sub _run_callback { sub($){shift} }
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine _run_callback: called CC=1 SCAR=0.0
63
64 sub _transform
65 3 ▶{
Subroutine _transform: called CC=1 SCAR=0.0
66 3 my ($class, $name, $ctx) = @_;
67
68 3 $ctx->skip_declarator;
69 3 my $length = Devel::Declare::toke_scan_str($ctx->offset);
70 3 my $string = Devel::Declare::get_lex_stuff;
71 3 Devel::Declare::clear_lex_stuff;
72 3 my $linestr = $ctx->get_linestr;
73 3 my $quoted = substr $linestr, $ctx->offset, $length;
74 3 my $spaced = '';
75 3 $quoted =~ m{^(\s*)}sm;
76 3 $spaced = $1;
77 3 my $new = sprintf $QuoteOp{$name}, join q[],
78 q[qw],
79 $spaced,
80 substr($quoted, length($spaced), 1),
81 $string,
82 substr($quoted, -1, 1);
83 3 substr($linestr, $ctx->offset, $length) = $new;
84 3 $ctx->set_linestr($linestr);
85 # my $s = $ctx->get_linestr;
86 # warn ">>> $s\n";
87 3 return 1;
88 }
89  
90 4 __PACKAGE__
91 __END__
↑ Summary