blib/lib/Catmandu/Fix/Inlineable.pm

filter: Statementstmt 96.4% 27 / 28 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 94.8% 37 / 39 CC 3 SCAR 3.9
CC
3
Cov
94%
__ANON__
2.1
import
2.0
BEGIN
1.0
CRAP 1.5
« blib/lib/Catmandu/Fix/Condition/SimpleCompareTest.pm ↑ Summary blib/lib/Catmandu/Importer/Text.pm »
1 package Catmandu::Fix::Inlineable;
2  
3 89 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 89 our $VERSION = '1.0201_02';
6  
7 89 ▶use Clone ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 89 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 89 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 89 requires 'fix';
12  
13 sub import {
14 105 ▶ my $target = caller;
Subroutine import: called CC=2 SCAR=7.0
15 105 my ($fix, %opts) = @_;
16  
17 105 ▶ if (my $sym = $opts{as}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sym = $opts{"as"}) 2 103 105
18 my $sub = sub {
19 2 ▶ my $data = shift;
Subroutine __ANON__: called CC=2 SCAR=7.6
20 2 ▶ if ($opts{clone}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"clone"}) 0 2 2
21 0 $data = Clone::clone($data);
22 }
23 2 $fix->new(@_)->fix($data);
24 2 };
25 89 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
26 2 *{"${target}::$sym"} = $sub;
27 }
28 }
29  
30 89 1;
31  
32 __END__
33  
34 =pod
35  
36 =head1 NAME
37  
38 Catmandu::Fix::Inlineable - Role for all Catmandu fixes that can be inlined
39  
40 =head1 SYNOPSIS
41  
42 package Catmandu::Fix::my_fix1;
43  
44 use Catmandu::Sane;
45 use Moo;
46  
47 with 'Catmandu::Fix::Inlineable';
48  
49 sub fix {
50 my ($self, $data) = @_;
51 ....FIXER GENERATING CODE....
52 $data
53 }
54  
55 package Catmandu::Fix::my_fix2;
56  
57 use Catmandu::Sane;
58 use Moo;
59  
60 # Catmandu::Fix::Base automatically is Inlineable
61 with 'Catmandu::Fix::Base';
62  
63 sub emit {
64 my ($self, $fixer) = @_;
65 ....FIXER GENERATING CODE....
66 }
67  
68 package main;
69  
70 use Catmandu::Fix::my_fix1 as => 'my_fix1';
71 use Catmandu::Fix::my_fix2 as => 'my_fix2';
72  
73 my $data = {};
74  
75 $data = my_fix1($data);
76 $data = my_fix2($data);
77  
78 =head1 SEE ALSO
79  
80 For more information how to create fixes read the following two blog posts:
81  
82 http://librecat.org/catmandu/2014/03/14/create-a-fixer.html
83 http://librecat.org/catmandu/2014/03/26/creating-a-fixer-2.html
84  
85 =cut
« blib/lib/Catmandu/Fix/Condition/SimpleCompareTest.pm ↑ Summary blib/lib/Catmandu/Importer/Text.pm »