File Coverage

lib/App/Sandy/Base.pm
Criterion Covered Total %
statement 98 105 93.3
branch 15 24 62.5
condition n/a
subroutine 20 20 100.0
pod 0 1 0.0
total 133 150 88.6


line stmt bran cond sub pod time code
1             package App::Sandy::Base;
2             # ABSTRACT: Policy and base module to App::Sandy project.
3              
4 6     6   2328 use 5.014;
  6         48  
5 6     6   24 use strict;
  6         12  
  6         144  
6 6     6   34 use warnings FATAL => 'all';
  6         7  
  6         347  
7 6     6   3173 use utf8 ();
  6         76  
  6         159  
8 6     6   32 use feature ();
  6         11  
  6         94  
9 6     6   12845 use true ();
  6         76560  
  6         150  
10 6     6   39 use Carp ();
  6         11  
  6         98  
11 6     6   3499 use IO::Handle;
  6         39657  
  6         280  
12 6     6   2836 use Try::Tiny ();
  6         11722  
  6         146  
13 6     6   2947 use Hook::AfterRuntime;
  6         12116  
  6         334  
14 6     6   3813 use Import::Into;
  6         14351  
  6         180  
15 6     6   3445 use Data::OptList;
  6         44842  
  6         46  
16 6     6   235 use Module::Runtime 'use_module';
  6         12  
  6         45  
17 6     6   3021 use namespace::autoclean;
  6         69139  
  6         24  
18              
19             our $VERSION = '0.25'; # VERSION
20              
21             BEGIN {
22             $SIG{'__DIE__'} = sub {
23 120 50       437175 if($^S) {
24 0         0 return;
25             }
26 120 50       405 Carp::confess(@_) if $ENV{DEBUG};
27 120         1420 die(@_);
28 6     6   2034 };
29             }
30              
31             # To ensure STDERR will be utf8 encoded
32 6     6   3086 binmode STDERR, ":encoding(utf8)";
  6         82  
  6         31  
33              
34             # Enable auto-flush
35             STDERR->autoflush(1);
36              
37             our $LOG_VERBOSE = 1;
38              
39             sub log_msg {
40 152     152 0 564 my ($msg) = @_;
41 152 50       368 return if not defined $msg;
42 152         313 chomp $msg;
43 152 50       598 say STDERR $msg if $LOG_VERBOSE;
44             }
45              
46             sub import {
47 220     220   909699 my ($class, @opts) = @_;
48 220         723 my $caller = caller;
49              
50             # Import as in Moder::Perl
51 220         1922 strict->import;
52 220         17089 feature->import(':5.14');
53 220         1676 utf8->import($caller);
54 220         1969 true->import;
55 220         495403 Carp->import::into($caller);
56 220         62604 Try::Tiny->import::into($caller);
57              
58             # Custom handy function
59 220         48376 do {
60 6     6   47 no strict 'refs'; ## no critic
  6         13  
  6         3168  
61 220         859 *{"${caller}\:\:log_msg"} = \&log_msg;
  220         1157  
62 220         545 *{"${caller}\:\:LOG_VERBOSE"} = \$LOG_VERBOSE;
  220         1047  
63             };
64              
65             @opts = @{
66 220         546 Data::OptList::mkopt(
  220         1004  
67             \@opts,
68             )
69             };
70              
71 220         7634 my @no_clean;
72 220         576 for my $opt_spec (@opts) {
73 213         608 my ($opt, $opt_args) = @$opt_spec;
74 213 50       1107 if ($opt eq 'dont_clean') {
    100          
    100          
    50          
75 0 0       0 if (!$opt_args) {
76 0         0 Carp::carp "ignoring dont_clean option without arrayref of subroutine names to keep";
77 0         0 next;
78             }
79 0         0 push @no_clean, @$opt_args;
80             } elsif ($opt eq 'class') {
81 108         4449 require Moose;
82 108         2826755 require MooseX::StrictConstructor;
83 108         140649 require MooseX::UndefTolerant;
84 108         126521 require App::Sandy::Types;
85 108         932 Moose->import({into=>$caller});
86 108         750783 MooseX::StrictConstructor->import({into=>$caller});
87 108         414019 MooseX::UndefTolerant->import({into=>$caller});
88 108         510248 App::Sandy::Types->import({into=>$caller});
89             after_runtime {
90 108     108   27612 $caller->meta->make_immutable;
91             }
92 108         897 } elsif ($opt eq 'role') {
93 45         284 require Moose::Role;
94 45         174 require App::Sandy::Types;
95 45         488 Moose::Role->import({into=>$caller});
96 45         243662 App::Sandy::Types->import({into=>$caller});
97             } elsif ($opt eq 'test') {
98 60         215 use_module('Test::Most')->import::into($caller);
99 60 100       347640 if ($opt_args) {
100 10         40 for my $opt_arg (@$opt_args) {
101 10 100       55 if ($opt_arg eq 'class_load') {
    50          
102 5         30 use_module('Test::Class::Load')->import::into($caller, 't/lib');
103             } elsif ($opt_arg eq 'class_base') {
104 5         20 my @classes = qw(Test::Class Class::Data::Inheritable);
105 5         20 use_module('base')->import::into($caller, @classes);
106             } else {
107 0         0 Carp::carp "Ignoring unknown test option '$_'";
108             }
109             }
110             }
111             } else {
112 0         0 Carp::carp "Ignoring unknown import option '$_'";
113             }
114             }
115              
116             #This must come after anything else that might change warning
117             # levels in the caller (e.g. Moose)
118 220         66978 warnings->import('FATAL'=>'all');
119              
120 220         1983 namespace::autoclean->import(
121             -cleanee => $caller,
122             -except => \@no_clean,
123             );
124              
125 220         63825 return;
126             }
127              
128             1; ## --- end module App::Sandy::Base
129              
130             __END__
131              
132             =pod
133              
134             =encoding UTF-8
135              
136             =head1 NAME
137              
138             App::Sandy::Base - Policy and base module to App::Sandy project.
139              
140             =head1 VERSION
141              
142             version 0.25
143              
144             =head1 AUTHORS
145              
146             =over 4
147              
148             =item *
149              
150             Thiago L. A. Miller <tmiller@mochsl.org.br>
151              
152             =item *
153              
154             J. Leonel Buzzo <lbuzzo@mochsl.org.br>
155              
156             =item *
157              
158             Felipe R. C. dos Santos <fsantos@mochsl.org.br>
159              
160             =item *
161              
162             Helena B. Conceição <hconceicao@mochsl.org.br>
163              
164             =item *
165              
166             Rodrigo Barreiro <rbarreiro@mochsl.org.br>
167              
168             =item *
169              
170             Gabriela Guardia <gguardia@mochsl.org.br>
171              
172             =item *
173              
174             Fernanda Orpinelli <forpinelli@mochsl.org.br>
175              
176             =item *
177              
178             Rafael Mercuri <rmercuri@mochsl.org.br>
179              
180             =item *
181              
182             Rodrigo Barreiro <rbarreiro@mochsl.org.br>
183              
184             =item *
185              
186             Pedro A. F. Galante <pgalante@mochsl.org.br>
187              
188             =back
189              
190             =head1 COPYRIGHT AND LICENSE
191              
192             This software is Copyright (c) 2023 by Teaching and Research Institute from Sírio-Libanês Hospital.
193              
194             This is free software, licensed under:
195              
196             The GNU General Public License, Version 3, June 2007
197              
198             =cut