X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMouse.pm;h=708b0a55fea49e377ddd885f1bd40cea5e741896;hb=eae8075956ba01581ea7488b4ddb2506db1111da;hp=c529135f91715e4846dd42383f9e84d66eaf921d;hpb=7a024324a4bc51897bafff2b9cf86998ae7cbe98;p=gitmo%2FMouse.git diff --git a/lib/Mouse.pm b/lib/Mouse.pm index c529135..708b0a5 100644 --- a/lib/Mouse.pm +++ b/lib/Mouse.pm @@ -1,11 +1,34 @@ -#!/usr/bin/env perl + package Mouse; use strict; use warnings; +use 5.006; use base 'Exporter'; -our $VERSION = '0.10'; -use 5.006; +our $VERSION; +our $PurePerl; + +BEGIN { + $VERSION = '0.12'; + + if ($ENV{MOUSE_DEBUG}) { + *DEBUG = sub (){ 1 }; + } else { + *DEBUG = sub (){ 0 }; + } + + if (! defined $PurePerl && $ENV{MOUSE_PUREPERL} && $ENV{MOUSE_PUREPERL} =~ /^(.+)$/) { + $PurePerl = $1; + } + + if (! $PurePerl) { + local $@; + local $^W = 0; + require XSLoader; + $PurePerl = ! eval{ XSLoader::load(__PACKAGE__, $VERSION); 1 }; + warn "Failed to load XS mode: $@" if $@; # && Mouse::DEBUG(); + } +} use Carp 'confess'; use Mouse::Util 'blessed'; @@ -69,11 +92,12 @@ sub with { my $meta = Mouse::Meta::Class->initialize(caller); my $role = shift; + my $args = shift || {}; - confess "Mouse::Role only supports 'with' on individual roles at a time" if @_; + confess "Mouse::Role only supports 'with' on individual roles at a time" if @_ || !ref $args; Mouse::load_class($role); - $role->meta->apply($meta); + $role->meta->apply($meta, %$args); } sub import { @@ -90,7 +114,7 @@ sub import { no warnings 'redefine'; *{$caller.'::meta'} = sub { $meta }; - Mouse->export_to_level(1, @_); + __PACKAGE__->export_to_level( 1, @_); } sub unimport { @@ -299,9 +323,10 @@ Whether this attribute is required to have a value. If the attribute is lazy or has a builder, then providing a value for the attribute in the constructor is optional. -=item init_arg => Str +=item init_arg => Str | Undef -Allows you to use a different key name in the constructor. +Allows you to use a different key name in the constructor. If undef, the +attribue can't be passed to the constructor. =item default => Value | CodeRef @@ -359,6 +384,11 @@ context. In scalar context, the reference is returned (NOT the list length or bucket status). You must specify an appropriate type constraint to use auto_deref. +=item lazy_build => 0|1 + +Automatically define lazy => 1 as well as builder => "_build_$attr", clearer => +"clear_$attr', predicate => 'has_$attr' unless they are already defined. + =back =head2 confess error -> BOOM