Split role application to a module like Moose
[gitmo/Mouse.git] / lib / Mouse / Util.pm
index 076ca34..393bccf 100644 (file)
@@ -38,13 +38,13 @@ BEGIN{
 
             not_supported
 
-            does meta dump
+            does meta throw_error dump
         )],
         groups => {
             default => [], # export no functions by default
 
             # The ':meta' group is 'use metaclass' for Mouse
-            meta    => [qw(does meta dump)],
+            meta    => [qw(does meta dump throw_error)],
         },
     );
 
@@ -67,7 +67,7 @@ BEGIN{
             Mouse::Util->import({ into => 'Mouse::Meta::Method::Accessor::XS'    }, ':meta');
             return 1;
         } || 0;
-        #warn $@ if $@;
+        warn $@ if $@ && $ENV{MOUSE_XS};
     }
 
     if(!$xs){
@@ -337,6 +337,22 @@ sub meta :method{
     return Mouse::Meta::Class->initialize(ref($_[0]) || $_[0]);
 }
 
+# general throw_error() method
+# $o->throw_error($msg, depth => $leve, longmess => $croak_or_confess)
+sub throw_error :method {
+    my($self, $message, %args) = @_;
+
+    local $Carp::CarpLevel  = $Carp::CarpLevel + 1 + ($args{depth} || 0);
+    local $Carp::MaxArgNums = 20; # default is 8, usually we use named args which gets messier though
+
+    if(exists $args{longmess} && !$args{longmess}) {
+        Carp::croak($message);
+    }
+    else{
+        Carp::confess($message);
+    }
+}
+
 # general dump() method
 sub dump :method {
     my($self, $maxdepth) = @_;
@@ -346,6 +362,7 @@ sub dump :method {
     $dd->Maxdepth(defined($maxdepth) ? $maxdepth : 3);
     $dd->Indent(1);
     $dd->Sortkeys(1);
+    $dd->Quotekeys(0);
     return $dd->Dump();
 }
 
@@ -395,7 +412,7 @@ The same as C<Mouse::Util::class_of()>.
 
 =head2 Class::MOP functions
 
-The followign functions are not exportable.
+The following functions are not exportable.
 
 =head3 C<< Mouse::Util::is_class_loaded($classname) -> Bool >>