Created
July 29, 2018 04:52
-
-
Save vti/5bda255a23b02cd31abc6d2b1a7126ab to your computer and use it in GitHub Desktop.
Custom oop bundle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package MyClass; | |
use oop -class => 1, -types => [qw/Int/]; | |
has 'foo', is => 'ro', is => Int, required => 1; | |
package MyRole; | |
use oop -role => 1; | |
requires 'foo'; | |
package MyPackage; | |
use oop; | |
sub enjoy_latest_features($foo) { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package oop; | |
use strict; | |
use warnings; | |
use mro; | |
use experimental; | |
use Import::Into; | |
sub import { | |
my ($class, %args) = @_; | |
my $caller = scalar caller; | |
mro->import; | |
warnings->import; | |
strict->import; | |
experimental->import::into($caller, 'signatures'); | |
mro::set_mro($caller, 'c3'); | |
if ($args{'-class'}) { | |
require Moo; | |
Moo->import::into($caller); | |
experimental->import::into($caller, 'signatures'); | |
} | |
if ($args{'-role'}) { | |
require Moo::Role; | |
Moo::Role->import::into($caller); | |
experimental->import::into($caller, 'signatures'); | |
} | |
if (my $types = $args{'-types'}) { | |
require Types::Standard; | |
Types::Standard->import::into($caller, @$types); | |
} | |
} | |
sub unimport { | |
warnings->unimport; | |
strict->unimport; | |
experimental->unimport; | |
} | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment