| 1 | # | ||
| 2 | # Copyright (C) 2015-2023 Joelle Maslak | ||
| 3 | # All Rights Reserved - See License | ||
| 4 | # | ||
| 5 | |||
| 6 | package JCM::Boilerplate; | ||
| 7 | # ABSTRACT: Default Boilerplate for Joelle Maslak's Code | ||
| 8 | $JCM::Boilerplate::VERSION = '2.231980'; | ||
| 9 | use strict; | ||
| 10 | use warnings; | ||
| 11 | |||
| 12 | |||
| 13 | use v5.22; | ||
| 14 | use strict; | ||
| 15 | |||
| 16 | use feature 'signatures'; | ||
| 17 | no warnings 'experimental::signatures'; | ||
| 18 | |||
| 19 | no warnings 'experimental::re_strict'; | ||
| 20 | use re 'strict'; | ||
| 21 | |||
| 22 | use English; | ||
| 23 | use Import::Into; | ||
| 24 | use Smart::Comments; | ||
| 25 | use re; | ||
| 26 | |||
| 27 | sub import ( $self, $type = 'script' ) { | ||
| 28 | ### assert: ($type =~ m/^(?:class|role|script)$/ms) | ||
| 29 | |||
| 30 | my $target = caller; | ||
| 31 | |||
| 32 | strict->import::into($target); | ||
| 33 | warnings->import::into($target); | ||
| 34 | autodie->import::into($target); | ||
| 35 | |||
| 36 | my ($ver) = "$PERL_VERSION" =~ m/^v(\d+\.\d+)\..*$/; | ||
| 37 | feature->import::into( $target, ":$ver" ); | ||
| 38 | |||
| 39 | utf8->import::into($target); # Allow UTF-8 Source | ||
| 40 | |||
| 41 | if ( $type eq 'class' ) { | ||
| 42 | Moose->import::into($target); | ||
| 43 | Moose::Util::TypeConstraints->import::into($target); | ||
| 44 | MooseX::StrictConstructor->import::into($target); | ||
| 45 | namespace::autoclean->import::into($target); | ||
| 46 | } elsif ( $type eq 'role' ) { | ||
| 47 | Moose::Role->import::into($target); | ||
| 48 | Moose::Util::TypeConstraints->import::into($target); | ||
| 49 | MooseX::StrictConstructor->import::into($target); | ||
| 50 | namespace::autoclean->import::into($target); | ||
| 51 | } else { | ||
| 52 | Feature::Compat::Class->import::into($target); | ||
| 53 | } | ||
| 54 | |||
| 55 | Carp->import::into($target); | ||
| 56 | English->import::into($target); | ||
| 57 | Smart::Comments->import::into( $target, '-ENV', '###' ); | ||
| 58 | |||
| 59 | feature->import::into( $target, 'postderef' ); # Not needed if feature bundle >= 5.23.1 | ||
| 60 | |||
| 61 | Feature::Compat::Defer->import::into($target); | ||
| 62 | Feature::Compat::Try->import::into($target); | ||
| 63 | |||
| 64 | # We haven't been using this | ||
| 65 | # feature->import::into($target, 'refaliasing'); | ||
| 66 | feature->import::into( $target, 'signatures' ); | ||
| 67 | |||
| 68 | feature->import::into( $target, 'unicode_strings' ); | ||
| 69 | # warnings->unimport::out_of($target, 'experimental::refaliasing'); | ||
| 70 | warnings->unimport::out_of( $target, 'experimental::signatures' ); | ||
| 71 | |||
| 72 | if ( $PERL_VERSION lt v5.24.0 ) { | ||
| 73 | warnings->unimport::out_of( $target, 'experimental::postderef' ); | ||
| 74 | } | ||
| 75 | |||
| 76 | # For "re 'strict'" feature | ||
| 77 | warnings->unimport::out_of( $target, 'experimental::re_strict' ); | ||
| 78 | re->import( 'strict' ); | ||
| 79 | |||
| 80 | if ( $PERL_VERSION ge v5.32.0 ) { | ||
| 81 | # Turn off indirect syntax | ||
| 82 | feature->unimport::out_of( $target, 'indirect' ); | ||
| 83 | |||
| 84 | # Turn on isa | ||
| 85 | feature->import::into( $target, 'isa' ); | ||
| 86 | warnings->unimport::out_of( $target, 'experimental::isa' ); | ||
| 87 | } | ||
| 88 | |||
| 89 | if ( $PERL_VERSION ge v5.34.0 ) { | ||
| 90 | # Turn off multidimensional "array" emulation | ||
| 91 | feature->unimport::out_of( $target, 'multidimensional' ); | ||
| 92 | |||
| 93 | # Turn off bareword filehandles | ||
| 94 | feature->unimport::out_of( $target, 'bareword_filehandles' ); | ||
| 95 | } | ||
| 96 | |||
| 97 | return; | ||
| 98 | } | ||
| 99 | |||
| 100 | 1; | ||
| 101 | |||
| 102 | __END__ | ||
| 103 | |||
| 104 | =pod | ||
| 105 | |||
| 106 | =encoding UTF-8 | ||
| 107 | |||
| 108 | =head1 NAME | ||
| 109 | |||
| 110 | JCM::Boilerplate - Default Boilerplate for Joelle Maslak's Code | ||
| 111 | |||
| 112 | =head1 VERSION | ||
| 113 | |||
| 114 | version 2.231980 | ||
| 115 | |||
| 116 | =head1 SYNOPSIS | ||
| 117 | |||
| 118 | use JCM::Boilerplate 'script'; | ||
| 119 | |||
| 120 | =head1 DESCRIPTION | ||
| 121 | |||
| 122 | This module serves two purposes. First, it sets some default imports, | ||
| 123 | and turns on the strictures I've come to rely upon. Secondly, it depends | ||
| 124 | on a number of other modules to aid in setting up new environments (I can | ||
| 125 | just do a "cpan JCM-Boilerplate" to install everything I need). | ||
| 126 | |||
| 127 | This module optionally takes one of two parameters, 'script', 'class', | ||
| 128 | or 'role'. If 'script' is specified, the module assumes that you do not | ||
| 129 | need Moose or MooseX modules. | ||
| 130 | |||
| 131 | =head1 WARNINGS | ||
| 132 | |||
| 133 | This module makes significant changes in the calling package! | ||
| 134 | |||
| 135 | In addition, this module should be incorporated into any project by | ||
| 136 | copying it into the project's library tree. This protects the project from | ||
| 137 | outside dependencies that may be undesired. | ||
| 138 | |||
| 139 | =head1 AUTHOR | ||
| 140 | |||
| 141 | Joelle Maslak <jmaslak@antelope.net> | ||
| 142 | |||
| 143 | =head1 COPYRIGHT AND LICENSE | ||
| 144 | |||
| 145 | This software is copyright (c) 2015-2023 by Joelle Maslak. | ||
| 146 | |||
| 147 | This is free software; you can redistribute it and/or modify it under | ||
| 148 | the same terms as the Perl 5 programming language system itself. | ||
| 149 | |||
| 150 | =cut |