Skip to content

Instantly share code, notes, and snippets.

@vti
Created July 29, 2018 04:52
Show Gist options
  • Save vti/5bda255a23b02cd31abc6d2b1a7126ab to your computer and use it in GitHub Desktop.
Save vti/5bda255a23b02cd31abc6d2b1a7126ab to your computer and use it in GitHub Desktop.
Custom oop bundle
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) {
}
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