X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMouse.pm;h=e1b01871a333f9c0ff6199d832bddfd1334a21a3;hb=e15d73d2969213b7c24ee8d01518746a7da40860;hp=f4cdfe0f990f423882572f2d804ef064797ffb7c;hpb=4aaa2ed6a8f267aa74bfbbab9b6880a900ca6063;p=gitmo%2FMouse.git diff --git a/lib/Mouse.pm b/lib/Mouse.pm index f4cdfe0..e1b0187 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.12'; -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'; @@ -78,6 +101,8 @@ sub with { } sub import { + my $class = shift; + strict->import; warnings->import; @@ -91,7 +116,15 @@ sub import { no warnings 'redefine'; *{$caller.'::meta'} = sub { $meta }; - Mouse->export_to_level(1, @_); + if (@_) { + __PACKAGE__->export_to_level( 1, $class, @_); + } else { + # shortcut for the common case of no type character + no strict 'refs'; + for my $keyword (@EXPORT) { + *{ $caller . '::' . $keyword } = *{__PACKAGE__ . '::' . $keyword}; + } + } } sub unimport {