# phpman > perldoc > Moose::Cookbook::Extending::Debugging_BaseClassRole

## NAME
    [Moose::Cookbook::Extending::Debugging_BaseClassRole](https://www.chedong.com/phpMan.php/perldoc/Moose%3A%3ACookbook%3A%3AExtending%3A%3ADebuggingBaseClassRole/markdown) - Providing a role for the base object class

## VERSION
    version 2.2200

## SYNOPSIS
      package [MooseX::Debugging](https://www.chedong.com/phpMan.php/perldoc/MooseX%3A%3ADebugging/markdown);

      use [Moose::Exporter](https://www.chedong.com/phpMan.php/perldoc/Moose%3A%3AExporter/markdown);

      [Moose::Exporter](https://www.chedong.com/phpMan.php/perldoc/Moose%3A%3AExporter/markdown)->setup_import_methods(
          base_class_roles => ['[MooseX::Debugging::Role::Object](https://www.chedong.com/phpMan.php/perldoc/MooseX%3A%3ADebugging%3A%3ARole%3A%3AObject/markdown)'],
      );

      package [MooseX::Debugging::Role::Object](https://www.chedong.com/phpMan.php/perldoc/MooseX%3A%3ADebugging%3A%3ARole%3A%3AObject/markdown);

      use [Moose::Role](https://www.chedong.com/phpMan.php/perldoc/Moose%3A%3ARole/markdown);

      sub BUILD {}
      after BUILD => sub {
          my $self = shift;

          warn "Made a new " . ( ref $self ) . " object\n";
      };

## DESCRIPTION
    In this example, we provide a role for the base object class that adds some simple debugging
    output. Every time an object is created, it spits out a warning saying what type of object it
    was.

    Obviously, a real debugging role would do something more interesting, but this recipe is all
    about how we apply that role.

    In this case, with the combination of [Moose::Exporter](https://www.chedong.com/phpMan.php/perldoc/Moose%3A%3AExporter/markdown) and [Moose::Util::MetaRole](https://www.chedong.com/phpMan.php/perldoc/Moose%3A%3AUtil%3A%3AMetaRole/markdown), we ensure that
    when a module does "use [MooseX::Debugging](https://www.chedong.com/phpMan.php/perldoc/MooseX%3A%3ADebugging/markdown)", it automatically gets the debugging role applied to
    its base object class.

    There are a few pieces of code worth looking at more closely.

      [Moose::Exporter](https://www.chedong.com/phpMan.php/perldoc/Moose%3A%3AExporter/markdown)->setup_import_methods(
          base_class_roles => ['[MooseX::Debugging::Role::Object](https://www.chedong.com/phpMan.php/perldoc/MooseX%3A%3ADebugging%3A%3ARole%3A%3AObject/markdown)'],
      );

    This creates an "import" method in the "[MooseX::Debugging](https://www.chedong.com/phpMan.php/perldoc/MooseX%3A%3ADebugging/markdown)" package. Since we are not actually
    exporting anything, we do not pass "setup_import_methods" any parameters related to exports, but
    we need to have an "import" method to ensure that our "init_meta" method is called. The
    "init_meta" is created by "setup_import_methods" for us, since we passed the "base_class_roles"
    parameter. The generated "init_meta" will in turn call
    [Moose::Util::MetaRole::apply_base_class_roles](https://www.chedong.com/phpMan.php/perldoc/Moose%3A%3AUtil%3A%3AMetaRole%3A%3Aapplybaseclassroles/markdown).

      sub BUILD {}
      after BUILD => sub {
          ...
      };

    Due to the way role composition currently works, if the class that a role is composed into
    contains a "BUILD" method, then that will override the "BUILD" method in any roles it composes,
    which is typically not what you want. Using a method modifier on "BUILD" avoids this issue,
    since method modifiers compose together rather than being overridden. Method modifiers require
    that a method exists in order to wrap, however, so we also provide a stub method to wrap if no
    "BUILD" method exists in the class.

## AUTHORS
    *   Stevan Little <<stevan@cpan.org>>

    *   Dave Rolsky <<autarch@urth.org>>

    *   Jesse Luehrs <<doy@cpan.org>>

    *   Shawn M Moore <<sartak@cpan.org>>

    *   יובל קוג'מן (Yuval Kogman) <<nothingmuch@woobling.org>>

    *   Karen Etheridge <<ether@cpan.org>>

    *   Florian Ragwitz <<rafl@debian.org>>

    *   Hans Dieter Pearcey <<hdp@cpan.org>>

    *   Chris Prather <<chris@prather.org>>

    *   Matt S Trout <<mstrout@cpan.org>>

## COPYRIGHT AND LICENSE
    This software is copyright (c) 2006 by Infinity Interactive, Inc.

    This is free software; you can redistribute it and/or modify it under the same terms as the Perl
    5 programming language system itself.

