use Carp 'confess';
use Scalar::Util 'blessed', 'weaken';
-our $VERSION = '0.82_02';
+our $VERSION = '0.90';
$VERSION = eval $VERSION;
our $AUTHORITY = 'cpan:STEVAN';
sub _new {
my $class = shift;
+
+ return Class::MOP::Class->initialize($class)->new_object(@_)
+ if $class ne __PACKAGE__;
+
my $options = @_ == 1 ? $_[0] : {@_};
bless {
# and a list of the methods
# associated with this attr
'associated_methods' => [],
+ # this let's us keep track of
+ # our order inside the associated
+ # class
+ 'insertion_order' => undef,
}, $class;
}
sub has_init_arg { defined($_[0]->{'init_arg'}) }
sub has_default { defined($_[0]->{'default'}) }
sub has_initializer { defined($_[0]->{'initializer'}) }
+sub has_insertion_order { defined($_[0]->{'insertion_order'}) }
sub accessor { $_[0]->{'accessor'} }
sub reader { $_[0]->{'reader'} }
sub init_arg { $_[0]->{'init_arg'} }
sub initializer { $_[0]->{'initializer'} }
sub definition_context { $_[0]->{'definition_context'} }
+sub insertion_order { $_[0]->{'insertion_order'} }
+sub _set_insertion_order { $_[0]->{'insertion_order'} = $_[1] }
# end bootstrapped away method section.
# (all methods below here are kept intact)
}
sub is_default_a_coderef {
- ('CODE' eq ref($_[0]->{'default'}))
+ my ($value) = $_[0]->{'default'};
+ return unless ref($value);
+ return ref($value) eq 'CODE' || (blessed($value) && $value->isa('Class::MOP::Method'));
}
sub default {
always return a subroutine reference, regardless of whether or not the
attribute is read- or write-only.
+=item B<< $attr->insertion_order >>
+
+If this attribute has been inserted into a class, this returns a zero
+based index regarding the order of insertion.
+
=back
=head2 Informational predicates
=item B<< $attr->has_builder >>
+=item B<< $attr->has_insertion_order >>
+
+This will be I<false> if this attribute has not be inserted into a class
+
=back
=head2 Value management