| File | /usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/metaclass.pm |
| Statements Executed | 263 |
| Statement Execution Time | 13.0ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 20 | 20 | 20 | 421µs | 3.17ms | metaclass::import |
| 1 | 1 | 1 | 14µs | 16µs | metaclass::BEGIN@4 |
| 1 | 1 | 1 | 8µs | 22µs | metaclass::BEGIN@5 |
| 1 | 1 | 1 | 7µs | 36µs | metaclass::BEGIN@7 |
| 1 | 1 | 1 | 7µs | 30µs | metaclass::BEGIN@8 |
| 1 | 1 | 1 | 4µs | 4µs | metaclass::BEGIN@14 |
| 0 | 0 | 0 | 0s | 0s | metaclass::__ANON__[:51] |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | |||||
| 2 | package metaclass; | ||||
| 3 | |||||
| 4 | 3 | 21µs | 2 | 19µs | # spent 16µs (14+3) within metaclass::BEGIN@4 which was called
# once (14µs+3µs) by Moose::Meta::TypeConstraint::BEGIN@6 at line 4 # spent 16µs making 1 call to metaclass::BEGIN@4
# spent 3µs making 1 call to strict::import |
| 5 | 3 | 23µs | 2 | 36µs | # spent 22µs (8+14) within metaclass::BEGIN@5 which was called
# once (8µs+14µs) by Moose::Meta::TypeConstraint::BEGIN@6 at line 5 # spent 22µs making 1 call to metaclass::BEGIN@5
# spent 14µs making 1 call to warnings::import |
| 6 | |||||
| 7 | 3 | 23µs | 2 | 66µs | # spent 36µs (7+29) within metaclass::BEGIN@7 which was called
# once (7µs+29µs) by Moose::Meta::TypeConstraint::BEGIN@6 at line 7 # spent 36µs making 1 call to metaclass::BEGIN@7
# spent 30µs making 1 call to Exporter::import |
| 8 | 3 | 43µs | 2 | 52µs | # spent 30µs (7+23) within metaclass::BEGIN@8 which was called
# once (7µs+23µs) by Moose::Meta::TypeConstraint::BEGIN@6 at line 8 # spent 30µs making 1 call to metaclass::BEGIN@8
# spent 23µs making 1 call to Exporter::import |
| 9 | |||||
| 10 | 1 | 3µs | our $VERSION = '0.98'; | ||
| 11 | 1 | 38µs | $VERSION = eval $VERSION; | ||
| 12 | 1 | 700ns | our $AUTHORITY = 'cpan:STEVAN'; | ||
| 13 | |||||
| 14 | 3 | 12.0ms | 1 | 4µs | # spent 4µs within metaclass::BEGIN@14 which was called
# once (4µs+0s) by Moose::Meta::TypeConstraint::BEGIN@6 at line 14 # spent 4µs making 1 call to metaclass::BEGIN@14 |
| 15 | |||||
| 16 | # spent 3.17ms (421µs+2.75) within metaclass::import which was called 20 times, avg 158µs/call:
# once (51µs+1.04ms) by Moose::Object::BEGIN@13 at line 15 of if.pm
# once (30µs+124µs) by Moose::Meta::Role::Composite::BEGIN@5 at line 5 of Moose/Meta/Role/Composite.pm
# once (30µs+121µs) by Moose::Meta::Role::BEGIN@6 at line 6 of Moose/Meta/Role.pm
# once (29µs+111µs) by Moose::Meta::TypeConstraint::BEGIN@6 at line 6 of Moose/Meta/TypeConstraint.pm
# once (20µs+100µs) by Moose::Meta::TypeConstraint::Union::BEGIN@6 at line 6 of Moose/Meta/TypeConstraint/Union.pm
# once (20µs+96µs) by Moose::Meta::TypeConstraint::Class::BEGIN@5 at line 5 of Moose/Meta/TypeConstraint/Class.pm
# once (17µs+96µs) by Moose::Meta::TypeConstraint::Registry::BEGIN@6 at line 6 of Moose/Meta/TypeConstraint/Registry.pm
# once (18µs+91µs) by Moose::Meta::Role::Application::BEGIN@5 at line 5 of Moose/Meta/Role/Application.pm
# once (22µs+85µs) by Moose::Meta::Role::Method::Required::BEGIN@6 at line 6 of Moose/Meta/Role/Method/Required.pm
# once (25µs+80µs) by Moose::Meta::Role::Application::RoleSummation::BEGIN@5 at line 5 of Moose/Meta/Role/Application/RoleSummation.pm
# once (16µs+86µs) by Moose::Meta::TypeCoercion::BEGIN@6 at line 6 of Moose/Meta/TypeCoercion.pm
# once (16µs+83µs) by Moose::Meta::TypeConstraint::Role::BEGIN@5 at line 5 of Moose/Meta/TypeConstraint/Role.pm
# once (16µs+82µs) by Moose::Meta::TypeConstraint::Enum::BEGIN@5 at line 5 of Moose/Meta/TypeConstraint/Enum.pm
# once (16µs+82µs) by Moose::Meta::TypeConstraint::DuckType::BEGIN@5 at line 5 of Moose/Meta/TypeConstraint/DuckType.pm
# once (16µs+79µs) by Moose::Meta::Role::Application::ToClass::BEGIN@5 at line 5 of Moose/Meta/Role/Application/ToClass.pm
# once (16µs+79µs) by Moose::Meta::Role::Application::ToRole::BEGIN@5 at line 5 of Moose/Meta/Role/Application/ToRole.pm
# once (17µs+79µs) by Moose::Meta::Role::Application::ToInstance::BEGIN@5 at line 5 of Moose/Meta/Role/Application/ToInstance.pm
# once (16µs+77µs) by Moose::Meta::TypeConstraint::Parameterized::BEGIN@5 at line 5 of Moose/Meta/TypeConstraint/Parameterized.pm
# once (16µs+77µs) by Moose::Meta::TypeConstraint::Parameterizable::BEGIN@5 at line 5 of Moose/Meta/TypeConstraint/Parameterizable.pm
# once (15µs+75µs) by Moose::Meta::TypeCoercion::Union::BEGIN@6 at line 6 of Moose/Meta/TypeCoercion/Union.pm | ||||
| 17 | 201 | 445µs | my ( $class, @args ) = @_; | ||
| 18 | |||||
| 19 | unshift @args, "metaclass" if @args % 2 == 1; | ||||
| 20 | my %options = @args; | ||||
| 21 | |||||
| 22 | my $metaclass = delete $options{metaclass}; | ||||
| 23 | |||||
| 24 | unless ( defined $metaclass ) { | ||||
| 25 | $metaclass = "Class::MOP::Class"; | ||||
| 26 | } else { | ||||
| 27 | Class::MOP::load_class($metaclass); # spent 44µs making 1 call to Class::MOP::load_class | ||||
| 28 | } | ||||
| 29 | |||||
| 30 | ($metaclass->isa('Class::MOP::Class')) # spent 31µs making 20 calls to UNIVERSAL::isa, avg 2µs/call | ||||
| 31 | || confess "The metaclass ($metaclass) must be derived from Class::MOP::Class"; | ||||
| 32 | |||||
| 33 | # make sure the custom metaclasses get loaded | ||||
| 34 | foreach my $key (grep { /_(?:meta)?class$/ } keys %options) { | ||||
| 35 | unless ( ref( my $class = $options{$key} ) ) { | ||||
| 36 | Class::MOP::load_class($class) | ||||
| 37 | } | ||||
| 38 | } | ||||
| 39 | |||||
| 40 | my $package = caller(); | ||||
| 41 | |||||
| 42 | # create a meta object so we can install &meta | ||||
| 43 | my $meta = $metaclass->initialize($package => %options); # spent 991µs making 19 calls to Class::MOP::Class::initialize, avg 52µs/call
# spent 960µs making 1 call to Moose::Meta::Class::initialize | ||||
| 44 | $meta->add_method('meta' => sub { | ||||
| 45 | # we must re-initialize so that it | ||||
| 46 | # works as expected in subclasses, | ||||
| 47 | # since metaclass instances are | ||||
| 48 | # singletons, this is not really a | ||||
| 49 | # big deal anyway. | ||||
| 50 | 43 | 356µs | 86 | 331µs | $metaclass->initialize((blessed($_[0]) || $_[0]) => %options) # spent 306µs making 43 calls to Class::MOP::Class::initialize, avg 7µs/call
# spent 25µs making 43 calls to Scalar::Util::blessed, avg 579ns/call |
| 51 | }); # spent 720µs making 20 calls to Class::MOP::Mixin::HasMethods::add_method, avg 36µs/call | ||||
| 52 | } | ||||
| 53 | |||||
| 54 | 1 | 10µs | 1; | ||
| 55 | |||||
| 56 | __END__ | ||||
| 57 | |||||
| 58 | =pod | ||||
| 59 | |||||
| 60 | =head1 NAME | ||||
| 61 | |||||
| 62 | metaclass - a pragma for installing and using Class::MOP metaclasses | ||||
| 63 | |||||
| 64 | =head1 SYNOPSIS | ||||
| 65 | |||||
| 66 | package MyClass; | ||||
| 67 | |||||
| 68 | # use Class::MOP::Class | ||||
| 69 | use metaclass; | ||||
| 70 | |||||
| 71 | # ... or use a custom metaclass | ||||
| 72 | use metaclass 'MyMetaClass'; | ||||
| 73 | |||||
| 74 | # ... or use a custom metaclass | ||||
| 75 | # and custom attribute and method | ||||
| 76 | # metaclasses | ||||
| 77 | use metaclass 'MyMetaClass' => ( | ||||
| 78 | 'attribute_metaclass' => 'MyAttributeMetaClass', | ||||
| 79 | 'method_metaclass' => 'MyMethodMetaClass', | ||||
| 80 | ); | ||||
| 81 | |||||
| 82 | # ... or just specify custom attribute | ||||
| 83 | # and method classes, and Class::MOP::Class | ||||
| 84 | # is the assumed metaclass | ||||
| 85 | use metaclass ( | ||||
| 86 | 'attribute_metaclass' => 'MyAttributeMetaClass', | ||||
| 87 | 'method_metaclass' => 'MyMethodMetaClass', | ||||
| 88 | ); | ||||
| 89 | |||||
| 90 | =head1 DESCRIPTION | ||||
| 91 | |||||
| 92 | This is a pragma to make it easier to use a specific metaclass | ||||
| 93 | and a set of custom attribute and method metaclasses. It also | ||||
| 94 | installs a C<meta> method to your class as well. | ||||
| 95 | |||||
| 96 | =head1 AUTHORS | ||||
| 97 | |||||
| 98 | Stevan Little E<lt>stevan@iinteractive.comE<gt> | ||||
| 99 | |||||
| 100 | =head1 COPYRIGHT AND LICENSE | ||||
| 101 | |||||
| 102 | Copyright 2006-2010 by Infinity Interactive, Inc. | ||||
| 103 | |||||
| 104 | L<http://www.iinteractive.com> | ||||
| 105 | |||||
| 106 | This library is free software; you can redistribute it and/or modify | ||||
| 107 | it under the same terms as Perl itself. | ||||
| 108 | |||||
| 109 | =cut |