Last active
December 26, 2015 14:39
-
-
Save ggl/7167741 to your computer and use it in GitHub Desktop.
Moo vs. Mo vs. Class::Tiny vs. Mojo::Base
This file contains hidden or 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
#!/usr/bin/env perl | |
package Boo; | |
use Moo; | |
has blah => ( is => 'ro' ); | |
sub bla { | |
my ($oh, @ah) = @_; | |
return join(' ', ucfirst($oh->blah), @ah); | |
} | |
1; | |
package Bo; | |
use Mo; | |
has blah => (); | |
sub bla { | |
my ($oh, @ah) = @_; | |
return join(' ', ucfirst($oh->blah), @ah); | |
} | |
1; | |
package Bct; | |
use strict; | |
use warnings; | |
use Class::Tiny qw(blah); | |
sub bla { | |
my ($oh, @ah) = @_; | |
return join(' ', ucfirst($oh->blah), @ah); | |
} | |
1; | |
package Bmb; | |
use Mojo::Base -base; | |
has blah => (); | |
sub bla { | |
my ($oh, @ah) = @_; | |
return join(' ', ucfirst($oh->blah), @ah); | |
}; | |
1; | |
package main; | |
use Benchmark qw(cmpthese); | |
cmpthese -1, { | |
moo => sub { | |
my $b = Boo->new(blah => 'blablabla'); | |
$b->bla('bla', 'blaaa!'); | |
}, | |
mo => sub { | |
my $b = Bo->new(blah => 'blablabla'); | |
$b->bla('bla', 'blaaa!'); | |
}, | |
ct => sub { | |
my $b = Bct->new(blah => 'blablabla'); | |
$b->bla('bla', 'blaaa!'); | |
}, | |
mb => sub { | |
my $b = Bmb->new(blah => 'blablabla'); | |
$b->bla('bla', 'blaaa!'); | |
} | |
}; |
This file contains hidden or 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 Bla; | |
use Mo; | |
has blah => (); | |
sub bla { | |
my ($oh, @ah) = @_; | |
return join(' ', ucfirst($oh->blah), @ah); | |
} | |
1; | |
package main; | |
my $b = Bla->new(blah => 'blablabla'); | |
print $b->bla('bla', 'blaaa!') . "\n"; |
This file contains hidden or 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 Blah; | |
use strict; | |
use warnings; | |
use Class::Tiny qw(blah); | |
sub bla { | |
my ($oh, @ah) = @_; | |
return join(' ', ucfirst($oh->blah), @ah); | |
} | |
1; | |
package main; | |
my $b = Blah->new(blah => 'blablabla'); | |
print $b->bla('bla', 'blaaa!') . "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment