lib/App/Sandy/Base.pm

filter: Statementstmt 81.8% 90 / 110 Branchbran 25.0% 6 / 24 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.4% 19 / 21 Podpod 0.0% 0 / 1 totaltotal 73.7% 115 / 156 CC 15 SCAR 20.4
CC
15
Cov
72%
import
18.6
log_msg
12.0
__ANON__
3.5
CRAP 7.7
« lib/App/Sandy/DB.pm ↑ Summary lib/App/Sandy/Types.pm »
1 package App::Sandy::Base;
2 # ABSTRACT: Policy and base module to App::Sandy project.
3  
4 1 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use utf8 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use feature ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use true ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use IO::Handle;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Try::Tiny ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Hook::AfterRuntime;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Import::Into;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Data::OptList;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Module::Runtime 'use_module';
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 1 our $VERSION = '0.25'; # VERSION
20  
21 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.4
22 4 ▶ $SIG{'__DIE__'} = sub {
Subroutine __ANON__: called CC=3 SCAR=12.5
23 4 ▶ if($^S) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^S) 0 4 4
24 0 return;
25 }
26 4 ▶ Carp::confess(@_) if $ENV{DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"DEBUG"} 0 4 4
27 4 die(@_);
28 1 };
29 }
30  
31 # To ensure STDERR will be utf8 encoded
32 1 ▶binmode STDERR, ":encoding(utf8)";
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 # Enable auto-flush
35 1 STDERR->autoflush(1);
36  
37 1 our $LOG_VERBOSE = 1;
38  
39 0 ▶sub log_msg {
Subroutine log_msg: not called CC=3 SCAR=24.8
Pod undocumented
40 0 my ($msg) = @_;
41 0 ▶ return if not defined $msg;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $msg 0 0 0
42 0 chomp $msg;
43 0 ▶ say STDERR $msg if $LOG_VERBOSE;
Branch: 1 branch
BranchTrueFalseTotal
if $App::Sandy::Base::LOG_VERBOSE 0 0 0
44 }
45  
46 50 ▶sub import {
Subroutine import: called CC=11 SCAR=29.2
47 50 my ($class, @opts) = @_;
48 50 my $caller = caller;
49  
50 # Import as in Moder::Perl
51 50 strict->import;
52 50 feature->import(':5.14');
53 50 utf8->import($caller);
54 50 true->import;
55 50 Carp->import::into($caller);
56 50 Try::Tiny->import::into($caller);
57  
58 # Custom handy function
59 50 do {
60 1 ▶ no strict 'refs'; ## no critic
Subroutine BEGIN: called CC=1 SCAR=0.0
61 50 *{"${caller}\:\:log_msg"} = \&log_msg;
62 50 *{"${caller}\:\:LOG_VERBOSE"} = \$LOG_VERBOSE;
63 };
64  
65 @opts = @{
66 50 Data::OptList::mkopt(
67 \@opts,
68 )
69 };
70  
71 50 my @no_clean;
72 50 for my $opt_spec (@opts) {
73 48 my ($opt, $opt_args) = @$opt_spec;
74 48 ▶ if ($opt eq 'dont_clean') {
Branch: 4 branches
BranchTrueFalseTotal
if ($opt eq 'dont_clean') { } 0 48 48
elsif ($opt eq 'class') { } 38 10 48
elsif ($opt eq 'role') { } 10 0 10
elsif ($opt eq 'test') { } 0 0 0
75 0 ▶ if (!$opt_args) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opt_args) 0 0 0
76 0 Carp::carp "ignoring dont_clean option without arrayref of subroutine names to keep";
77 0 next;
78 }
79 0 push @no_clean, @$opt_args;
80 } elsif ($opt eq 'class') {
81 38 require Moose;
82 38 require MooseX::StrictConstructor;
83 38 require MooseX::UndefTolerant;
84 38 require App::Sandy::Types;
85 38 Moose->import({into=>$caller});
86 38 MooseX::StrictConstructor->import({into=>$caller});
87 38 MooseX::UndefTolerant->import({into=>$caller});
88 38 App::Sandy::Types->import({into=>$caller});
89 0 ▶ after_runtime {
Subroutine __ANON__: not called CC=1 SCAR=6.9
90 0 $caller->meta->make_immutable;
91 }
92 0 } elsif ($opt eq 'role') {
93 10 require Moose::Role;
94 10 require App::Sandy::Types;
95 10 Moose::Role->import({into=>$caller});
96 10 App::Sandy::Types->import({into=>$caller});
97 } elsif ($opt eq 'test') {
98 0 use_module('Test::Most')->import::into($caller);
99 0 ▶ if ($opt_args) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt_args) 0 0 0
100 0 for my $opt_arg (@$opt_args) {
101 0 ▶ if ($opt_arg eq 'class_load') {
Branch: 2 branches
BranchTrueFalseTotal
if ($opt_arg eq 'class_load') { } 0 0 0
elsif ($opt_arg eq 'class_base') { } 0 0 0
102 0 use_module('Test::Class::Load')->import::into($caller, 't/lib');
103 } elsif ($opt_arg eq 'class_base') {
104 0 my @classes = qw(Test::Class Class::Data::Inheritable);
105 0 use_module('base')->import::into($caller, @classes);
106 } else {
107 0 Carp::carp "Ignoring unknown test option '$_'";
108 }
109 }
110 }
111 } else {
112 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 2 warnings->import('FATAL'=>'all');
119  
120 2 namespace::autoclean->import(
121 -cleanee => $caller,
122 -except => \@no_clean,
123 );
124  
125 2 return;
126 }
127  
128 1 1; ## --- end module App::Sandy::Base
129  
130 __END__
« lib/App/Sandy/DB.pm ↑ Summary lib/App/Sandy/Types.pm »