--- /dev/null
+#!perl
+# a moose using script for profiling
+# Usage: perl bench/profile.pl
+
+package Foo;
+use Moose;
+
+has aaa => (
+ is => 'rw',
+ isa => 'Str',
+);
+
+has bbb => (
+ is => 'rw',
+ isa => 'Str',
+);
+
+has ccc => (
+ is => 'rw',
+ isa => 'Str',
+);
+
+has ddd => (
+ is => 'rw',
+ isa => 'Str',
+);
+
+has eee => (
+ is => 'rw',
+ isa => 'Str',
+);
+
+__PACKAGE__->meta->make_immutable();
+
+
+package Bar;
+use Moose;
+
+extends 'Foo';
+
+has xaaa => (
+ is => 'rw',
+ isa => 'Str',
+);
+
+has xbbb => (
+ is => 'rw',
+ isa => 'Str',
+);
+
+has xccc => (
+ is => 'rw',
+ isa => 'Str',
+);
+
+has xddd => (
+ is => 'rw',
+ isa => 'Str',
+);
+
+has xeee => (
+ is => 'rw',
+ isa => 'Str',
+);
+
+__PACKAGE__->meta->make_immutable();
use strict;
use Benchmark qw(:all);
-my $module = 'Moose';
+my($count, $module) = @ARGV;
+$count ||= 10;
+$module ||= 'Moose';
-cmpthese timethese 10 => {
+cmpthese timethese $count => {
released => sub {
system( $^X, '-e', "require $module" ) == 0 or die;
},
+++ /dev/null
-#!perl -wd:NYTProf
-require Moose;
--- /dev/null
+#!perl -w
+# Usage: perl bench/profile.pl (no other options including -Mblib are reqired)
+
+use strict;
+
+my $script = 'bench/foo.pl';
+
+my $branch = do{
+ open my $in, '.git/HEAD' or die "Cannot open .git/HEAD: $!";
+ my $s = scalar <$in>;
+ chomp $s;
+ $s =~ s{^ref: \s+ refs/heads/}{}xms;
+ $s =~ s{/}{_}xmsg;
+ $s;
+};
+
+print "Profiling $branch ...\n";
+
+my @cmd = ($^X, '-Iblib/lib', '-Iblib/arch', $script);
+print "> @cmd\n";
+system(@cmd) == 0 or die "Cannot profile";
+
+@cmd = ($^X, '-S', 'nytprofhtml', '--out', "nytprof-$branch");
+print "> @cmd\n";
+system(@cmd) == 0 or die "Cannot profile";
my $found;
my %exceptions;
for my $class (@classes) {
- my $pmfile = _class_to_pmfile($class);
my $e = _try_load_one_class($class);
if ($e) {
+ my $pmfile = _class_to_pmfile($class);
$exceptions{$class} = $e;
last if $e !~ /^Can't locate \Q$pmfile\E in \@INC/;
}
# about the class which it is attached to
$attribute->attach_to_class($self);
+ my $attr_name = $attribute->name;
+
# then we remove attributes of a conflicting
# name here so that we can properly detach
# the old attr object, and remove any
# accessors it would have generated
- if ( $self->has_attribute($attribute->name) ) {
- $self->remove_attribute($attribute->name);
+ if ( $self->has_attribute($attr_name) ) {
+ $self->remove_attribute($attr_name);
} else {
$self->invalidate_meta_instances();
}
# get our count of previously inserted attributes and
# increment by one so this attribute knows its order
- my $order = (scalar keys %{$self->get_attribute_map}) - 1;
- $attribute->_set_insertion_order($order + 1);
+ my $order = (scalar keys %{$self->get_attribute_map});
+ $attribute->_set_insertion_order($order);
# then onto installing the new accessors
- $self->get_attribute_map->{$attribute->name} = $attribute;
+ $self->get_attribute_map->{$attr_name} = $attribute;
# invalidate package flag here
my $e = do {
$@;
};
if ( $e ) {
- $self->remove_attribute($attribute->name);
+ $self->remove_attribute($attr_name);
die $e;
}
=item * attributes
-An optional array reference of attributes.
-
-An attribute can be passed as an existing L<Class::MOP::Attribute>
-object, I<or> or as a hash reference of options which will be passed
-to the attribute metaclass's constructor.
+An optional array reference of L<Class::MOP::Attribute> objects.
=back
$default = '$instance->'.$attr->builder;
}
- if ( defined $attr->init_arg ) {
+ if ( defined(my $init_arg = $attr->init_arg) ) {
return (
- 'if(exists $params->{\'' . $attr->init_arg . '\'}){' . "\n" .
+ 'if(exists $params->{\'' . $init_arg . '\'}){' . "\n" .
$self->_meta_instance->inline_set_slot_value(
'$instance',
$attr->name,
- '$params->{\'' . $attr->init_arg . '\'}' ) . "\n" .
+ '$params->{\'' . $init_arg . '\'}' ) . "\n" .
'} ' . (!defined $default ? '' : 'else {' . "\n" .
$self->_meta_instance->inline_set_slot_value(
'$instance',