summaryrefslogtreecommitdiff
path: root/lib/Getopt/Dakkar/Style.pm
blob: 5246a9539a8c117a039156ab8514de5d23b3e217 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package Getopt::Dakkar::Style; 
use 5.026;
use strictures version => 2;
use true;
use Import::Into;
use Path::Tiny ();
 
# VERSION 
# ABSTRACT: simplify writing things in the right style 
 
sub use_types {
    my ($caller) = @_;
    require Types::Standard;
    require Type::Params;
 
    Types::Standard->import::into(
        $caller,
        "Any",
        "Item",
        "Bool",
        "Undef",
        "Defined",
        "Value",
        "Str",
        "Num",
        "Int",
        "ClassName",
        "RoleName",
        "Ref",
        "CodeRef",
        "RegexpRef",
        "FileHandle",
        "ArrayRef",
        "HashRef",
        "ScalarRef",
        "Object",
        "Maybe",
        "Map",
        "Optional",
        "Tuple",
        "Dict",
        "InstanceOf",
        "ConsumerOf",
        "HasMethods",
    );
 
    Type::Params->import::into($caller);
}
 
sub import {
    my $class = shift;
    my (@args) = @_;
    my $caller = caller();
 
    strict->import();
    feature->import::into($caller':5.26');
    Try::Tiny->import::into($caller);
    Carp->import::into($caller);
    true->import({ into =>  $caller });
    Getopt::Dakkar::X->import::into($caller);
 
    my %arg = map { $_ => 1 } @args;
    if ($arg{class}) {
        require Moo;
        Moo->import::into($caller);
        $arg{types}=1;
    }
    if ($arg{role}) {
        require Moo::Role;
        Moo::Role->import::into($caller);
        $arg{types}=1;
    }
    if ($arg{types}) {
        use_types($caller);
    }
    if ($arg{test}) {
        require Test::Most;
        require Test::Warnings;
        require lib;
        Test::Most->import::into($caller);
        Test::Warnings->import::into($caller);
        lib->import::into(
            $caller,
            Path::Tiny::path(__FILE__)->parent(4)->child('t/lib')->stringify,
        );
    }
 
    # This must come after anything else that might change warning 
    # levels in the caller (e.g. Moo) 
    strictures->import::into($caller,version=>2);
    # and then we disable warnings for the experimental features we 
    # want 
    experimental->import::into($caller,qw(postderef signatures));
 
    # Auto-clean up imported symbols 
    namespace::autoclean->import(
        -cleanee => $caller,
    );
 
    return;
}