X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMouse%2FPurePerl.pm;h=7d11a638aa7ee412c0dcdcdd9f738d8a7ebb37da;hb=ccb38d0b59fd3c82b5e5812a31de988fb9a4bf4f;hp=b601b2928e9eb3f41fe07472c930d2ce5974cfd4;hpb=7d96ae4dfb9f6806432c90c33bb2d3a5bf63a9a7;p=gitmo%2FMouse.git diff --git a/lib/Mouse/PurePerl.pm b/lib/Mouse/PurePerl.pm index b601b29..7d11a63 100644 --- a/lib/Mouse/PurePerl.pm +++ b/lib/Mouse/PurePerl.pm @@ -1,3 +1,5 @@ +package Mouse::PurePerl; + package Mouse::Util; @@ -77,9 +79,25 @@ sub get_code_ref{ package Mouse::Util::TypeConstraints; +use Scalar::Util qw(blessed looks_like_number openhandle); + +sub _generate_class_type_for{ + my($for_class, $name) = @_; + + my $predicate = sub{ blessed($_[0]) && $_[0]->isa($for_class) }; + + if(defined $name){ + no strict 'refs'; + *{ caller() . '::' . $name } = $predicate; + return; + } + + return $predicate; +} + + sub Any { 1 } sub Item { 1 } -sub Maybe { 1 } sub Bool { $_[0] ? $_[0] eq '1' : 1 } sub Undef { !defined($_[0]) } @@ -110,7 +128,10 @@ sub RoleName { (Mouse::Util::class_of($_[0]) || return 0)->isa('Mouse::Meta::R package Mouse::Meta::Module; -sub name { $_[0]->{package} } +sub name { $_[0]->{package} } + +sub _method_map { $_[0]->{methods} } +sub _attribute_map{ $_[0]->{attribute_map} } sub namespace{ my $name = $_[0]->{package}; @@ -118,6 +139,30 @@ sub namespace{ return \%{ $name . '::' }; } +sub add_method { + my($self, $name, $code) = @_; + + if(!defined $name){ + $self->throw_error('You must pass a defined name'); + } + if(!defined $code){ + $self->throw_error('You must pass a defined code'); + } + + if(ref($code) ne 'CODE'){ + $code = \&{$code}; # coerce + } + + $self->{methods}->{$name} = $code; # Moose stores meta object here. + + my $pkg = $self->name; + no strict 'refs'; + no warnings 'redefine', 'once'; + *{ $pkg . '::' . $name } = $code; + return; +} + + package Mouse::Meta::Class; @@ -141,6 +186,7 @@ sub get_roles { $_[0]->{roles} } package Mouse::Meta::Attribute; +use Mouse::Meta::Method::Accessor; # readers @@ -168,6 +214,8 @@ sub builder { $_[0]->{builder} } sub should_auto_deref { $_[0]->{auto_deref} } sub should_coerce { $_[0]->{coerce} } +sub documentation { $_[0]->{documentation} } + # predicates sub has_accessor { exists $_[0]->{accessor} } @@ -182,6 +230,10 @@ sub has_type_constraint { exists $_[0]->{type_constraint} } sub has_trigger { exists $_[0]->{trigger} } sub has_builder { exists $_[0]->{builder} } +sub has_documentation { exists $_[0]->{documentation} } + +sub accessor_metaclass(){ 'Mouse::Meta::Method::Accessor' } + package Mouse::Meta::TypeConstraint; @@ -191,10 +243,23 @@ sub message { $_[0]->{message} } sub _compiled_type_constraint{ $_[0]->{compiled_type_constraint} } -sub has_coercion{ exists $_[0]->{_compiled_type_coercion} } +sub _compiled_type_coercion { $_[0]->{_compiled_type_coercion} } -package - Mouse::Meta::Method::Accessor; +sub has_coercion{ exists $_[0]->{_compiled_type_coercion} } 1; __END__ + +=head1 NAME + +Mouse::PurePerl - A Mouse guts in pure Perl + +=head1 VERSION + +This document describes Mouse version 0.40_01 + +=head1 SEE ALSO + +L + +=cut