Last active
November 21, 2017 14:06
-
-
Save andrewalker/bff2d81a24c5b76af99f58f22a5d8763 to your computer and use it in GitHub Desktop.
init_meta weirdness
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 MyMooseExported; | |
use Moose (); | |
use Moose::Exporter; | |
use Log::Contextual::SimpleLogger; | |
use Log::Contextual qw( :log ), | |
-logger => Log::Contextual::SimpleLogger->new({ levels => [qw( debug )] }); | |
Moose::Exporter->setup_import_methods( | |
with_meta => ['my_has'], | |
as_is => ['some_method'], | |
also => 'Moose', | |
); | |
sub my_has { | |
log_debug { "in my_has" }; | |
} | |
sub some_method { | |
log_debug { "in some_method" }; | |
} | |
sub init_meta { | |
my ($package, %options) = @_; | |
my $meta = Moose->init_meta(%options); | |
#$meta->superclasses('MyMooseExported::Object'); | |
return $meta; | |
} | |
no Moose; | |
1; |
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 MyMooseExported::Object; | |
use Moose; | |
use Log::Contextual qw( :log ); | |
sub BUILD { | |
log_debug { "Being built" }; | |
} | |
__PACKAGE__->meta->make_immutable; | |
no Moose; | |
1; |
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 SomeClass; | |
use MyMooseExported; | |
use Log::Contextual qw( :log ); | |
log_debug { "going to call my_has" }; | |
my_has(); | |
log_debug { "going to call some_method" }; | |
some_method(); | |
log_debug { "I'm done now" }; | |
exit 0; | |
################################################### | |
# run me with: perl -I. -MSomeClass | |
# then uncomment line 24 of MyMooseExported, | |
# and run me again | |
################################################### |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment