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   1308 use 5.010;
  6         40  
5 6     6   32 use strict;
  6         7  
  6         136  
6 6     6   28 use warnings FATAL => 'all';
  6         8  
  6         267  
7 6     6   32 no warnings 'experimental::smartmatch';
  6         8  
  6         208  
8 6     6   2461 use utf8 ();
  6         79  
  6         434  
9 6     6   39 use feature ();
  6         12  
  6         90  
10 6     6   1446 use true ();
  6         52093  
  6         167  
11 6     6   42 use Carp ();
  6         12  
  6         82  
12 6     6   1981 use Try::Tiny ();
  6         10004  
  6         144  
13 6     6   1534 use namespace::autoclean;
  6         70225  
  6         44  
14 6     6   2540 use Hook::AfterRuntime;
  6         7137  
  6         349  
15 6     6   1425 use Import::Into;
  6         2479  
  6         160  
16 6     6   1395 use Data::OptList;
  6         29806  
  6         52  
17 6     6   216 use Module::Runtime 'use_module';
  6         12  
  6         54  
18              
19             our $VERSION = '0.05'; # VERSION
20              
21 6     6   2105 binmode STDERR, ":encoding(utf8)";
  6         62  
  6         30  
22             our $LOG_VERBOSE = 1;
23              
24             sub log_msg {
25 74     74 0 271 my ($msg) = @_;
26 74 50       226 return if not defined $msg;
27 74         180 chomp $msg;
28 74 50       258 say STDERR $msg if $LOG_VERBOSE;
29             }
30              
31             sub import {
32 133     133   704236 my ($class, @opts) = @_;
33 133         496 my $caller = caller;
34              
35             # Import as in Moder::Perl
36 133         1176 strict->import;
37 133         11279 feature->import(':5.10');
38 133         1368 utf8->import($caller);
39 133         1499 true->import;
40 133         253009 Carp->import::into($caller);
41 133         38761 Try::Tiny->import::into($caller);
42              
43             # Custom handy function
44 133         27285 do {
45 6     6   1197 no strict 'refs'; ## no critic
  6         12  
  6         2604  
46 133         449 *{"${caller}\:\:log_msg"} = \&log_msg;
  133         777  
47 133         390 *{"${caller}\:\:LOG_VERBOSE"} = \$LOG_VERBOSE;
  133         665  
48             };
49              
50             @opts = @{
51 133         315 Data::OptList::mkopt(
  133         650  
52             \@opts,
53             )
54             };
55              
56 133         4630 my @no_clean;
57 133         359 for my $opt_spec (@opts) {
58 132         413 my ($opt, $opt_args) = @$opt_spec;
59 132         288 given ($opt) {
60 132         529 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         388 when ('class') {
68 69         3014 require Moose;
69 69         2613488 require MooseX::StrictConstructor;
70 69         152203 require MooseX::UndefTolerant;
71 69         125060 require App::SimulateReads::Types;
72 69         717 Moose->import({into=>$caller});
73 69         506150 MooseX::StrictConstructor->import({into=>$caller});
74 69         313127 MooseX::UndefTolerant->import({into=>$caller});
75 69         413710 My::Types->import({into=>$caller});
76             after_runtime {
77 69     69   35223 $caller->meta->make_immutable;
78             }
79 69         715 }
80 63         154 when ('role') {
81 13         78 require Moose::Role;
82 13         54 require App::SimulateReads::Types;
83 13         149 Moose::Role->import({into=>$caller});
84 13         66781 My::Types->import({into=>$caller});
85             }
86 50         135 when ('test') {
87 50         200 use_module('Test::Most')->import::into($caller);
88 50 100       534090 if ($opt_args) {
89 10         100 for (@$opt_args) {
90 10         55 when ('class_load') {
91 5         35 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         20 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         119948 warnings->import('FATAL'=>'all');
112 133         3053 warnings->unimport('experimental::smartmatch');
113              
114 133         1460 namespace::autoclean->import(
115             -cleanee => $caller,
116             -except => \@no_clean,
117             );
118              
119 133         26838 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.05
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