File Coverage

lib/App/SimulateReads/Base.pm
Criterion Covered Total %
statement 100 108 92.5
branch 4 8 50.0
condition n/a
subroutine 19 19 100.0
pod 0 1 0.0
total 123 136 90.4


line stmt bran cond sub pod time code
1             package App::SimulateReads::Base;
2             # ABSTRACT: Policy and base module to App::SimulateReads project.
3              
4 6     6   1425 use 5.010;
  6         114  
5 6     6   44 use strict;
  6         46  
  6         194  
6 6     6   34 use warnings FATAL => 'all';
  6         6  
  6         474  
7 6     6   28 no warnings 'experimental::smartmatch';
  6         6  
  6         199  
8 6     6   2181 use utf8 ();
  6         70  
  6         118  
9 6     6   24 use feature ();
  6         11  
  6         66  
10 6     6   1249 use true ();
  6         44631  
  6         150  
11 6     6   45 use Carp ();
  6         6  
  6         76  
12 6     6   1983 use Try::Tiny ();
  6         9245  
  6         120  
13 6     6   1445 use namespace::autoclean;
  6         67148  
  6         28  
14 6     6   1845 use Hook::AfterRuntime;
  6         6744  
  6         275  
15 6     6   3084 use Import::Into;
  6         2334  
  6         144  
16 6     6   1389 use Data::OptList;
  6         26521  
  6         40  
17 6     6   177 use Module::Runtime 'use_module';
  6         17  
  6         34  
18              
19             our $VERSION = '0.06'; # VERSION
20              
21 6     6   1894 binmode STDERR, ":encoding(utf8)";
  6         62  
  6         31  
22             our $LOG_VERBOSE = 1;
23              
24             sub log_msg {
25 74     74 0 263 my ($msg) = @_;
26 74 50       195 return if not defined $msg;
27 74         160 chomp $msg;
28 74 50       202 say STDERR $msg if $LOG_VERBOSE;
29             }
30              
31             sub import {
32 133     133   672427 my ($class, @opts) = @_;
33 133         415 my $caller = caller;
34              
35             # Import as in Moder::Perl
36 133         961 strict->import;
37 133         8695 feature->import(':5.10');
38 133         1075 utf8->import($caller);
39 133         1132 true->import;
40 133         205423 Carp->import::into($caller);
41 133         32670 Try::Tiny->import::into($caller);
42              
43             # Custom handy function
44 133         24563 do {
45 6     6   958 no strict 'refs'; ## no critic
  6         15  
  6         2434  
46 133         405 *{"${caller}\:\:log_msg"} = \&log_msg;
  133         716  
47 133         343 *{"${caller}\:\:LOG_VERBOSE"} = \$LOG_VERBOSE;
  133         585  
48             };
49              
50             @opts = @{
51 133         297 Data::OptList::mkopt(
  133         630  
52             \@opts,
53             )
54             };
55              
56 133         4181 my @no_clean;
57 133         395 for my $opt_spec (@opts) {
58 132         460 my ($opt, $opt_args) = @$opt_spec;
59 132         240 given ($opt) {
60 132         568 when ('dont_clean') {
61 0 0       0 if (!$opt_args) {
62 0         0 Carp::carp "ignoring dont_clean option without arrayref of subroutine names to keep";
63 0         0 next;
64             }
65 0         0 push @no_clean, @$opt_args;
66             }
67 132         349 when ('class') {
68 69         3159 require Moose;
69 69         2142863 require MooseX::StrictConstructor;
70 69         115135 require MooseX::UndefTolerant;
71 69         101635 require App::SimulateReads::Types;
72 69         551 Moose->import({into=>$caller});
73 69         394466 MooseX::StrictConstructor->import({into=>$caller});
74 69         226630 MooseX::UndefTolerant->import({into=>$caller});
75 69         285328 App::SimulateReads::Types->import({into=>$caller});
76             after_runtime {
77 69     69   29371 $caller->meta->make_immutable;
78             }
79 69         506 }
80 63         162 when ('role') {
81 13         73 require Moose::Role;
82 13         52 require App::SimulateReads::Types;
83 13         113 Moose::Role->import({into=>$caller});
84 13         60424 App::SimulateReads::Types->import({into=>$caller});
85             }
86 50         105 when ('test') {
87 50         190 use_module('Test::Most')->import::into($caller);
88 50 100       479245 if ($opt_args) {
89 10         40 for (@$opt_args) {
90 10         45 when ('class_load') {
91 5         30 use_module('Test::Class::Load')->import::into($caller, 't/lib');
92             }
93 5         15 when ('class_base') {
94 5         15 my @classes = qw(Test::Class Class::Data::Inheritable);
95 5         15 use_module('base')->import::into($caller, @classes);
96             }
97 0         0 default {
98 0         0 Carp::carp "Ignoring unknown test option '$_'";
99             }
100             }
101             }
102             }
103 0         0 default {
104 0         0 Carp::carp "Ignoring unknown import option '$_'";
105             }
106             }
107             }
108              
109             #This must come after anything else that might change warning
110             # levels in the caller (e.g. Moose)
111 133         88099 warnings->import('FATAL'=>'all');
112 133         2129 warnings->unimport('experimental::smartmatch');
113              
114 133         1254 namespace::autoclean->import(
115             -cleanee => $caller,
116             -except => \@no_clean,
117             );
118              
119 133         22603 return;
120             }
121              
122             1; ## --- end module App::SimulateReads::Base
123              
124             __END__
125              
126             =pod
127              
128             =encoding UTF-8
129              
130             =head1 NAME
131              
132             App::SimulateReads::Base - Policy and base module to App::SimulateReads project.
133              
134             =head1 VERSION
135              
136             version 0.06
137              
138             =head1 AUTHOR
139              
140             Thiago L. A. Miller <tmiller@mochsl.org.br>
141              
142             =head1 COPYRIGHT AND LICENSE
143              
144             This software is Copyright (c) 2017 by Teaching and Research Institute from Sírio-Libanês Hospital.
145              
146             This is free software, licensed under:
147              
148             The GNU General Public License, Version 3, June 2007
149              
150             =cut