| 1 | # ############################################################################## | ||
| 2 | # # Script : Modern::PBP::Moose # | ||
| 3 | # # -------------------------------------------------------------------------- # | ||
| 4 | # # Copyright : Free under 'GNU General Public License' or 'Artistic License' # | ||
| 5 | # # Authors : JVBSOFT - Jürgen von Brietzke 0.001 - 1.200 # | ||
| 6 | # # Version : 1.200 14.Feb.2016 # | ||
| 7 | # # -------------------------------------------------------------------------- # | ||
| 8 | # # Function : Loading essential Perl Moose modules in the namespace of the # | ||
| 9 | # # caller. # | ||
| 10 | # # -------------------------------------------------------------------------- # | ||
| 11 | # # Language : PERL 5 (V) 5.12.xx - 5.22.xx # | ||
| 12 | # # Coding : ISO 8859-15 / Latin-9 UNIX-lineendings # | ||
| 13 | # # Standards : Perl-Best-Practices severity 1 (brutal) # | ||
| 14 | # # -------------------------------------------------------------------------- # | ||
| 15 | # # Pragmas : namespace::autoclean # | ||
| 16 | # # -------------------------------------------------------------------------- # | ||
| 17 | # # Module : Moose ActivePerl-CORE-Module # | ||
| 18 | # # Moose::Exporter # | ||
| 19 | # # Moose::Util::TypeConstraints # | ||
| 20 | # # ------------------------------------------------------------- # | ||
| 21 | # # Hook::AfterRuntime ActivePerl-REPO-Module # | ||
| 22 | # # Modern::PBP::Perl # | ||
| 23 | # # MooseX::AttributeShortcuts # | ||
| 24 | # # MooseX::DeclareX # | ||
| 25 | # # MooseX::DeclareX::Keyword::interface # | ||
| 26 | # # MooseX::DeclareX::Plugin::abstract # | ||
| 27 | # # MooseX::DeclareX::Plugin::singleton # | ||
| 28 | # # MooseX::DeclareX::Privacy # | ||
| 29 | # # MooseX::HasDefault::RO # | ||
| 30 | # ############################################################################## | ||
| 31 | |||
| 32 | package Modern::PBP::Moose 1.200; | ||
| 33 | |||
| 34 | # ############################################################################## | ||
| 35 | |||
| 36 | 3 | ▶ | use 5.012; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 37 | |||
| 38 | 3 | ▶ | use namespace::autoclean; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 39 | |||
| 40 | 3 | ▶ | use Hook::AfterRuntime; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 41 | 3 | ▶ | use Moose; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 42 | 3 | ▶ | use Moose::Exporter; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 43 | 3 | ▶ | use Moose::Util::TypeConstraints; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 44 | 3 | ▶ | use MooseX::AttributeShortcuts; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 45 | 3 | ▶ | use MooseX::DeclareX; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 46 | 3 | ▶ | use MooseX::HasDefaults::RO; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 47 | 0 | ▶ | use Modern::PBP::Moose::Role; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 48 | use Modern::PBP::Perl; | ||
| 49 | |||
| 50 | # ############################################################################## | ||
| 51 | |||
| 52 | our ( $IMPORT, $PBP ); | ||
| 53 | |||
| 54 | # ############################################################################## | ||
| 55 | |||
| 56 | my ( $import, $unimport, $init_meta ) = Moose::Exporter->build_import_methods( | ||
| 57 | install => ['unimport'], | ||
| 58 | ); | ||
| 59 | $IMPORT = $import; | ||
| 60 | |||
| 61 | Moose::Exporter->setup_import_methods( also => ['Moose'] ); | ||
| 62 | |||
| 63 | # ############################################################################## | ||
| 64 | # # Function | Replaces the 'import' method of 'Moose::Exporter' # | ||
| 65 | # # ----------+------------+-------------------------------------------------- # | ||
| 66 | # # Parameter | Object | Class-Name # | ||
| 67 | # # | Str | Parameters passed class # | ||
| 68 | # # ----------+------------+-------------------------------------------------- # | ||
| 69 | # # Result | none # | ||
| 70 | # ############################################################################## | ||
| 71 | |||
| 72 | sub import { | ||
| 73 | |||
| 74 | my ( $class, $parameter ) = @ARG; | ||
| 75 | |||
| 76 | my $caller_class = scalar caller; | ||
| 77 | |||
| 78 | $PBP = q{no_pbp}; | ||
| 79 | if ( defined $parameter ) { | ||
| 80 | if ( $parameter =~ /(?:no_pbp|pbp)/smx ) { | ||
| 81 | if ( $parameter eq q{pbp} ) { | ||
| 82 | no strict qw{refs}; | ||
| 83 | no warnings; ## no critic qw{ProhibitNoWarnings} | ||
| 84 | ${ $caller_class . '::pbp' } = q{pbp}; | ||
| 85 | use warnings; | ||
| 86 | use strict; | ||
| 87 | } | ||
| 88 | $PBP = splice @ARG, 1, 1; | ||
| 89 | } | ||
| 90 | } | ||
| 91 | |||
| 92 | return $class->$IMPORT( { into => $caller_class } ); | ||
| 93 | |||
| 94 | } ## end of sub import | ||
| 95 | |||
| 96 | # ############################################################################## | ||
| 97 | # # Function | Loading essential Perl Moose modules in the namespace # | ||
| 98 | # # ----------+------------+-------------------------------------------------- # | ||
| 99 | # # Parameter | Object | Class-Name # | ||
| 100 | # # | Hash | Parameters passed class # | ||
| 101 | # # ----------+------------+-------------------------------------------------- # | ||
| 102 | # # Result | none # | ||
| 103 | # ############################################################################## | ||
| 104 | |||
| 105 | sub init_meta { | ||
| 106 | |||
| 107 | my $class = shift; | ||
| 108 | my %params = @ARG; | ||
| 109 | |||
| 110 | my $for_class = $params{for_class}; | ||
| 111 | my $caller = scalar caller; | ||
| 112 | |||
| 113 | # --- All keywords for 'MooseX::DeclareX' ----------------------------------- | ||
| 114 | my @keywords = ( | ||
| 115 | qw{class clean extends role with}, 'is dirty', 'is mutable', | ||
| 116 | qw{after around augment before method override}, | ||
| 117 | qw{try catch}, | ||
| 118 | qw{exception}, | ||
| 119 | qw{interface namespace}, | ||
| 120 | ); | ||
| 121 | |||
| 122 | # --- All plugins for 'MooseX::DeclareX' ------------------------------------ | ||
| 123 | my @plugins = ( | ||
| 124 | qw{private protected public std_constants}, | ||
| 125 | qw{build guard having imports postprocess preprocess test_case types}, | ||
| 126 | qw{abstract singleton}, | ||
| 127 | ); | ||
| 128 | |||
| 129 | # --- Parameter for 'MooseX::DeclareX' -------------------------------------- | ||
| 130 | my %declarex = ( | ||
| 131 | keyword => [@keywords], | ||
| 132 | plugins => [@plugins], | ||
| 133 | types => [ -Moose ], | ||
| 134 | ); | ||
| 135 | |||
| 136 | # --- Import of all packages for 'Moose'-classes ---------------------------- | ||
| 137 | Moose->init_meta(@ARG); | ||
| 138 | Moose::Util::TypeConstraints->import( { into => $for_class } ); | ||
| 139 | MooseX::AttributeShortcuts->init_meta(@ARG); | ||
| 140 | MooseX::HasDefaults::RO->import( { into => $for_class } ); | ||
| 141 | $_->setup_for( $for_class, %declarex, provided_by => $caller ) | ||
| 142 | for MooseX::DeclareX->_keywords( \%declarex ); | ||
| 143 | if ( $PBP eq q{pbp} ) { | ||
| 144 | Modern::PBP::Moose::Role->import( { into => $for_class } ); | ||
| 145 | } | ||
| 146 | |||
| 147 | # --- Cleanup of the namespace at the end of calling class ------------------ | ||
| 148 | namespace::autoclean->import( -cleanee => $for_class ); | ||
| 149 | after_runtime { $for_class->meta->make_immutable }; | ||
| 150 | |||
| 151 | return; | ||
| 152 | |||
| 153 | } ## end of sub init_meta | ||
| 154 | |||
| 155 | # ############################################################################## | ||
| 156 | |||
| 157 | no Moose; | ||
| 158 | no Moose::Util::TypeConstraints; | ||
| 159 | |||
| 160 | # ############################################################################## | ||
| 161 | # # E N D # | ||
| 162 | # ############################################################################## | ||
| 163 | 1; | ||
| 164 | __END__ | ||