forked from ingydotnet/mo-pm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5369280
commit 3041848
Showing
6 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package Mo::Mouse;$M="Mo::"; | ||
$VERSION=0.28; | ||
*{$M.'Mouse::e'}=sub{my($P,$e)=@_;$P=~s/::$//;%$e=(M=>1);require Mouse;Mouse->import({into=>$P});Mouse::Util::MetaRole::apply_metaroles(for=>$P,class_metaroles=>{attribute=>['Attr::Trait']},)};BEGIN{package Attr::Trait;use Mouse::Role;around _process_options=>sub{my$orig=shift;my$c=shift;my($n,$o)=@_;$o->{is}||='rw';$o->{lazy}||=1 if defined$o->{default}or defined$o->{builder};$c->$orig(@_)};$INC{'Attr/Trait.pm'}=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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
=encoding utf8 | ||
|
||
=head1 Name | ||
|
||
Mo::Mouse - Use Mouse instead of Mo | ||
|
||
=head1 Synopsis | ||
|
||
use Mo 'Mouse'; | ||
has foo => (); | ||
|
||
=head1 Description | ||
|
||
If you use L<Mo> and want to try L<Mouse> without adding C<is> and C<lazy> | ||
options to all your attributes you can just do this: | ||
|
||
use Mo 'Mouse'; | ||
use foo => (); | ||
|
||
and everything should work, but now uses Mouse instead of Mo for everything. | ||
|
||
=cut |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package Mo::Mouse;$MoPKG = "Mo::"; | ||
$VERSION = 0.28; | ||
|
||
*{$MoPKG.'Mouse::e'} = sub { | ||
my ($caller_pkg, $exports) = @_; | ||
$caller_pkg =~ s/::$//; | ||
%$exports = (M => 1); | ||
require Mouse; | ||
Mouse->import({into => $caller_pkg}); | ||
Mouse::Util::MetaRole::apply_metaroles( | ||
for => $caller_pkg, | ||
class_metaroles => { attribute => ['Attr::Trait'] }, | ||
); | ||
}; | ||
|
||
BEGIN { | ||
package Attr::Trait; | ||
use Mouse::Role; | ||
|
||
around _process_options => sub { | ||
my $orig = shift; | ||
my $class = shift; | ||
my ($name, $options) = @_; | ||
|
||
$options->{is} ||= 'rw'; | ||
$options->{lazy} ||= 1 | ||
if defined $options->{default} or | ||
defined $options->{builder}; | ||
|
||
$class->$orig(@_); | ||
}; | ||
$INC{'Attr/Trait.pm'} = 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use Test::More tests => 4; | ||
|
||
{ | ||
package Foo; | ||
use Mo 'Mouse'; | ||
|
||
has foo => (); | ||
has bar => (default => 'I like pie!'); | ||
} | ||
|
||
my $f = Foo->new(foo => 42); | ||
die @Foo::ISA; | ||
|
||
is $f->foo, 42, 'Normal'; | ||
is $f->{bar}, undef, 'before (lazy)'; | ||
is $f->bar, 'I like pie!', 'default'; | ||
is $f->{bar}, 'I like pie!', 'after'; | ||
|