Test that lazy defaults get coerced the same as non-lazy ones
[gitmo/Role-Tiny.git] / benchmark / class_factory
index 1b2658d..af4b9e7 100644 (file)
@@ -85,7 +85,12 @@ for (1, 2) {
   print "Perl $], take $_:\n";
 
   # if forking must run for certain number of cycles, cputime doesn't work
-  cmpthese ( $opts->{subprocess} ? 15 : -1 , $tasks );
+  foreach my $type (sort keys %$attrs_to_bench) {
+    print "Benchming ${type}:\n";
+    my %these = map { (split ' ', $_)[0] => $tasks->{$_} }
+      grep /${type}$/, keys %$tasks;
+    cmpthese ( $opts->{subprocess} ? 15 : -1 , \%these );
+  }
   print "\n";
 }
 
@@ -94,9 +99,6 @@ exit 0; # the end
 sub _add_moosey_has {
   my ($name, $base, $attr_type) = @_;
 
-  # this works only with Moo, not with Moose, not with Mouse
-  return if ($attr_type =~ /qsub/ and $name !~ /moo\b/ );
-
   my @to_eval;
 
   for (1 .. $opts->{pregenerate} ) {
@@ -114,14 +116,14 @@ sub _add_moosey_has {
       }
 
       $perl .= '__PACKAGE__->meta->make_immutable;'
-        if $name !~ /moo\b/;
+        if $name !~ /^moo(_XS)?$/;
 
       $counters->{accessors} = 0
         unless $opts->{unique};
 
       if ($opts->{run}) {
-        $perl .= 'package main;';
-        $perl .= "our \$foo = $class->$_; $class->$_(1); our \$foo = $class->$_;"
+        $perl .= "\$::obj = $class->new;";
+        $perl .= "\$::foo = \$::obj->$_; \$::obj->$_(1); \$::foo = \$::obj->$_;"
           for @attr_names;
       }
     }