Skip to content

Commit

Permalink
Use new/cleaner Mo::default
Browse files Browse the repository at this point in the history
  • Loading branch information
ingydotnet committed Feb 26, 2013
1 parent 3faba11 commit cfcad1b
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 47 deletions.
23 changes: 9 additions & 14 deletions README
Expand Up @@ -3,13 +3,13 @@ NAME

SYNOPSIS
# file t/testml/encode.tml
%TestML 1.0
%TestML 0.1.0

Title = 'Tests for AcmeEncode';
Plan = 3;
Title = 'Tests for AcmeEncode'
Plan = 3

*text.apply_rot13 == *rot13;
*text.apply_md5 == *md5;
*text.apply_rot13 == *rot13
*text.apply_md5 == *md5

=== Encode some poetry
--- text
Expand All @@ -32,18 +32,13 @@ SYNOPSIS

To run this test you would have a normal test file that looks like this:

use TestML::Runtime::TAP;
use TestML;
use t::Bridge;

TestML::Runtime::TAP->new(
TestML->new(
testml => 'testml/encode.tml',
bridge => 't::Bridge',
)->run();

or more simply:

use TestML -run,
-testml => 'testml/encode.tml',
-bridge => 't::Bridge';
)->run;

The apply_* functions are defined in the bridge class that is specified
outside this test (t/Bridge.pm).
Expand Down
6 changes: 3 additions & 3 deletions lib/TestML.pm
Expand Up @@ -40,11 +40,11 @@ package TestML::Lite;
use TestML::Mo;
extends 'TestML';

has compiler => ( default => sub {'TestML::Compiler::Lite'} );
has library => ( default => sub {[
has compiler => 'TestML::Compiler::Lite';
has library => [
'TestML::Library::Lite',
'TestML::Library::Debug',
]} );
];
# TODO - We *might* want a TestML::Runtime::Lite

1;
Expand Down
4 changes: 2 additions & 2 deletions lib/TestML/AST.pm
Expand Up @@ -4,8 +4,8 @@ extends 'Pegex::Tree';

use TestML::Runtime;

has points => default => sub{[]};
has function => default => sub { TestML::Function->new };
has points => [];
has function => sub { TestML::Function->new };

# sub final {
# my ($self, $match, $top) = @_;
Expand Down
2 changes: 1 addition & 1 deletion lib/TestML/Compiler.pm
Expand Up @@ -5,7 +5,7 @@ use TestML::Grammar;
use TestML::AST;
use Pegex::Parser;

has base => ();
has base => '.';

sub compile {
my $self = shift;
Expand Down
4 changes: 2 additions & 2 deletions lib/TestML/Mo.pm
Expand Up @@ -8,7 +8,7 @@
package TestML::Mo;
# use Mo qw'build default builder xxx import';
# The following line of code was produced from the previous line by
# Mo::Inline version 0.32
no warnings;my$M=__PACKAGE__.'::';*{$M.Object::new}=sub{bless{@_[1..$#_]},$_[0]};*{$M.import}=sub{import warnings;$^H|=1538;my($P,%e,%o)=caller.'::';shift;eval"no Mo::$_",&{$M.$_.::e}($P,\%e,\%o,\@_)for@_;return if$e{M};%e=(extends,sub{eval"no $_[0]()";@{$P.ISA}=$_[0]},has,sub{my$n=shift;my$m=sub{$#_?$_[0]{$n}=$_[1]:$_[0]{$n}};@_=(default,@_)if!($#_%2);$m=$o{$_}->($m,$n,@_)for sort keys%o;*{$P.$n}=$m},%e,);*{$P.$_}=$e{$_}for keys%e;@{$P.ISA}=$M.Object};*{$M.'build::e'}=sub{my($P,$e)=@_;$e->{new}=sub{$c=shift;my$s=bless{@_},$c;my@B;do{@B=($c.::BUILD,@B)}while($c)=@{$c.::ISA};exists&$_&&&$_($s)for@B;$s}};*{$M.'default::e'}=sub{my($P,$e,$o)=@_;$o->{default}=sub{my($m,$n,%a)=@_;exists$a{default}or return$m;my$d=$a{default};my$gen=ref($d)eq 'HASH'?sub{+{%$d}}:ref($d)eq 'ARRAY'?sub{[@$d]}:ref($d)eq 'CODE'?$d:sub{$d};sub{$#_?$m->(@_):!exists$_[0]{$n}?$_[0]{$n}=$gen->(@_):$m->(@_)}}};*{$M.'builder::e'}=sub{my($P,$e,$o)=@_;$o->{builder}=sub{my($m,$n,%a)=@_;my$b=$a{builder}or return$m;sub{$#_?$m->(@_):!exists$_[0]{$n}?$_[0]{$n}=$_[0]->$b:$m->(@_)}}};use constant XXX_skip=>1;my$dm='YAML::XS';*{$M.'xxx::e'}=sub{my($P,$e)=@_;$e->{WWW}=sub{require XXX;local$XXX::DumpModule=$dm;XXX::WWW(@_)};$e->{XXX}=sub{require XXX;local$XXX::DumpModule=$dm;XXX::XXX(@_)};$e->{YYY}=sub{require XXX;local$XXX::DumpModule=$dm;XXX::YYY(@_)};$e->{ZZZ}=sub{require XXX;local$XXX::DumpModule=$dm}};my$i=\&import;*{$M.import}=sub{(@_==2 and not $_[1])?pop@_:@_==1?push@_,grep!/import/,@f:();goto&$i};@f=qw[build default builder xxx import];use strict;use warnings;
# Mo::Inline version 0.33
no warnings;my$M=__PACKAGE__.'::';*{$M.Object::new}=sub{bless{@_[1..$#_]},$_[0]};*{$M.import}=sub{import warnings;$^H|=1538;my($P,%e,%o)=caller.'::';shift;eval"no Mo::$_",&{$M.$_.::e}($P,\%e,\%o,\@_)for@_;return if$e{M};%e=(extends,sub{eval"no $_[0]()";@{$P.ISA}=$_[0]},has,sub{my$n=shift;my$m=sub{$#_?$_[0]{$n}=$_[1]:$_[0]{$n}};@_=(default,@_)if!($#_%2);$m=$o{$_}->($m,$n,@_)for sort keys%o;*{$P.$n}=$m},%e,);*{$P.$_}=$e{$_}for keys%e;@{$P.ISA}=$M.Object};*{$M.'build::e'}=sub{my($P,$e)=@_;$e->{new}=sub{$c=shift;my$s=bless{@_},$c;my@B;do{@B=($c.::BUILD,@B)}while($c)=@{$c.::ISA};exists&$_&&&$_($s)for@B;$s}};*{$M.'default::e'}=sub{my($P,$e,$o)=@_;$o->{default}=sub{my($m,$n,%a)=@_;exists$a{default}or return$m;my($d,$r)=$a{default};my$g='HASH'eq($r=ref$d)?sub{+{%$d}}:'ARRAY'eq$r?sub{[@$d]}:'CODE'eq$r?$d:sub{$d};sub{$#_?$m->(@_):!exists$_[0]{$n}?$_[0]{$n}=$g->(@_):$m->(@_)}}};*{$M.'builder::e'}=sub{my($P,$e,$o)=@_;$o->{builder}=sub{my($m,$n,%a)=@_;my$b=$a{builder}or return$m;sub{$#_?$m->(@_):!exists$_[0]{$n}?$_[0]{$n}=$_[0]->$b:$m->(@_)}}};use constant XXX_skip=>1;my$dm='YAML::XS';*{$M.'xxx::e'}=sub{my($P,$e)=@_;$e->{WWW}=sub{require XXX;local$XXX::DumpModule=$dm;XXX::WWW(@_)};$e->{XXX}=sub{require XXX;local$XXX::DumpModule=$dm;XXX::XXX(@_)};$e->{YYY}=sub{require XXX;local$XXX::DumpModule=$dm;XXX::YYY(@_)};$e->{ZZZ}=sub{require XXX;local$XXX::DumpModule=$dm}};my$i=\&import;*{$M.import}=sub{(@_==2 and not$_[1])?pop@_:@_==1?push@_,grep!/import/,@f:();goto&$i};@f=qw[build default builder xxx import];use strict;use warnings;

our $DumpModule = 'YAML';
47 changes: 23 additions & 24 deletions lib/TestML/Runtime.pm
Expand Up @@ -7,19 +7,19 @@ use TestML::Mo;
our $self;

has testml => ();
has bridge => ( default => sub {'main'} );
has library => ( default => sub {[
has bridge => 'main';
has library => [
'TestML::Library::Standard',
'TestML::Library::Debug',
]} );
has compiler => ( default => sub {'TestML::Compiler'} );
has base => ();
has skip => ();
has required => ( default => sub {[]} );
];
has compiler => 'TestML::Compiler';
has base => '.';
has skip => 0;
has required => [];

has function => (); # Current function executing
has planned => default => sub {0}; # plan() has been called
has test_number => default => sub {0}; # Number of tests run so far
has function => ();
has planned => 0;
has test_number => 0;

sub BUILD {
my $self = $TestML::Runtime::self = shift;
Expand Down Expand Up @@ -386,12 +386,11 @@ sub slurp {
package TestML::Function;
use TestML::Mo;

has type => default => sub {'Func'}; # Functions are TestML typed objects
# XXX Make this a featherweight reference.
has signature => default => sub {[]}; # Input variable names
has namespace => default => sub {{}}; # Lexical scoped variable stash
has statements => default => sub {[]}; # Exexcutable code statements
has data => default => sub{[]}; # Data section scoped to this function
has type => 'Func'; # Functions are TestML typed objects
has signature => []; # Input variable names
has namespace => {}; # Lexical scoped variable stash
has statements => []; # Exexcutable code statements
has data => []; # Data section scoped to this function

# Runtime pointers to current objects.
has expression => ();
Expand Down Expand Up @@ -431,38 +430,38 @@ sub forgetvar {
package TestML::Statement;
use TestML::Mo;

has expression => default => sub {TestML::Expression->new};
has expression => sub {TestML::Expression->new};
has assertion => ();
has points => default => sub {[]};
has points => [];

#-----------------------------------------------------------------------------
package TestML::Expression;
use TestML::Mo;

has units => default => sub {[]};
has units => [];
has error => ();

#-----------------------------------------------------------------------------
package TestML::Assertion;
use TestML::Mo;

has name => ();
has expression => default => sub {TestML::Expression->new};
has expression => sub {TestML::Expression->new};

#-----------------------------------------------------------------------------
package TestML::Call;
use TestML::Mo;

has name => ();
has args => default => sub {[]};
has explicit_call => default => 0;
has args => [];
has explicit_call => 0;

#-----------------------------------------------------------------------------
package TestML::Block;
use TestML::Mo;

has label => default => sub {''};
has points => default => sub {{}};
has label => '';
has points => {};

#-----------------------------------------------------------------------------
package TestML::Point;
Expand Down
2 changes: 1 addition & 1 deletion lib/TestML/Runtime/TAP.pm
Expand Up @@ -13,7 +13,7 @@ if ($TestML::Test::Differences) {
};
}

has test_builder => default => sub { Test::Builder->new };
has test_builder => sub { Test::Builder->new };

sub title {
my $self = shift;
Expand Down

0 comments on commit cfcad1b

Please sign in to comment.