# phpman > info > Type::Tiny::Manual::UsingWithClassTiny

[Type::Tiny::Manual::UsUseriContribuType::Tiny::Manual](https://www.chedong.com/phpMan.php/perldoc/Type%3A%3ATiny%3A%3AManual%3A%3AUsUseriContribuType%3A%3ATiny%3A%3AManual/markdown)::[UsingWithClassTiny(3pm)](https://www.chedong.com/phpMan.php/man/UsingWithClassTiny/3pm/markdown)

NAME
       [Type::Tiny::Manual::UsingWithClassTiny](https://www.chedong.com/phpMan.php/perldoc/Type%3A%3ATiny%3A%3AManual%3A%3AUsingWithClassTiny/markdown) - use of [Type::Tiny](https://www.chedong.com/phpMan.php/perldoc/Type%3A%3ATiny/markdown) with
       [Class::Tiny](https://www.chedong.com/phpMan.php/perldoc/Class%3A%3ATiny/markdown)

MANUAL
       [Class::Tiny](https://www.chedong.com/phpMan.php/perldoc/Class%3A%3ATiny/markdown) is an even-smaller-than-Moo class builder.

       Let's translate the classic Horse class from Moo to [Class::Tiny](https://www.chedong.com/phpMan.php/perldoc/Class%3A%3ATiny/markdown).

       Moo:

         package Horse {
           use Moo;
           use [Types::Standard](https://www.chedong.com/phpMan.php/perldoc/Types%3A%3AStandard/markdown) qw( Str Num ArrayRef );
           use [namespace::autoclean](https://www.chedong.com/phpMan.php/perldoc/namespace%3A%3Aautoclean/markdown);

           has name       => ( is => 'ro', isa => Str, required => 1 );
           has gender     => ( is => 'ro', isa => Str );
           has age        => ( is => 'rw', isa => Num );
           has children   => (
             is       => 'ro',
             isa      => ArrayRef,
             default  => sub { return [] },
           );
         }

       [Class::Tiny](https://www.chedong.com/phpMan.php/perldoc/Class%3A%3ATiny/markdown):

         package Horse {
           use [Class::Tiny](https://www.chedong.com/phpMan.php/perldoc/Class%3A%3ATiny/markdown) qw( gender age ), {
             name     => sub { die "name is required"; },
             children => sub { return [] },
           };
           use [Types::Standard](https://www.chedong.com/phpMan.php/perldoc/Types%3A%3AStandard/markdown) qw( Str Num ArrayRef Dict Optional slurpy Any);
           use [Type::Params](https://www.chedong.com/phpMan.php/perldoc/Type%3A%3AParams/markdown) qw( wrap_methods compile );
           use [namespace::autoclean](https://www.chedong.com/phpMan.php/perldoc/namespace%3A%3Aautoclean/markdown);

           # type checks
           wrap_methods(
             BUILD    => [Dict[
               name       => Str,
               gender     => Optional[Str],
               age        => Optional[Num],
               children   => Optional[ArrayRef],
               slurpy Any,
             ]],
             name     => [],
             gender   => [],
             age      => Optional[Num],
             children => [],
           );
         }

       What's going on here?

       Well, [Class::Tiny](https://www.chedong.com/phpMan.php/perldoc/Class%3A%3ATiny/markdown), after it has built a new object, will do this:

         $self->BUILD($args);

       (Technically, it calls "BUILD" not just for the current class, but for
       all parent classes too.) We can hook onto this in order to check type
       constraints for the constructor.

       We use "wrap_methods" from [Type::Params](https://www.chedong.com/phpMan.php/perldoc/Type%3A%3AParams/markdown) to wrap the original "BUILD"
       method (which doesn't exist, so "wrap_methods" will just assume an
       empty sub) with a type check for $args. The type check is just a Dict
       that checks the class's required and optional attributes and includes
       slurpy Any at the end to be flexible for subclasses adding new
       attributes.

       Then we wrap the "name", "gender", and "children" methods with checks
       to make sure they're only being called as getters, and we wrap "age",
       allowing it to be called as a setter with a Num.

       There are also a couple of CPAN modules that can help you out.

   [Class::Tiny::ConstrainedAccessor](https://www.chedong.com/phpMan.php/perldoc/Class%3A%3ATiny%3A%3AConstrainedAccessor/markdown)
       [Class::Tiny::ConstrainedAccessor](https://www.chedong.com/phpMan.php/perldoc/Class%3A%3ATiny%3A%3AConstrainedAccessor/markdown) creates a "BUILD" and accessors that
       enforce [Type::Tiny](https://www.chedong.com/phpMan.php/perldoc/Type%3A%3ATiny/markdown) constraints.  Attribute types are passed to
       [Class::Tiny::ConstrainedAccessor](https://www.chedong.com/phpMan.php/perldoc/Class%3A%3ATiny%3A%3AConstrainedAccessor/markdown); attribute defaults are passed to
       [Class::Tiny](https://www.chedong.com/phpMan.php/perldoc/Class%3A%3ATiny/markdown).

         package Horse {
           use [Types::Standard](https://www.chedong.com/phpMan.php/perldoc/Types%3A%3AStandard/markdown) qw( Str Num ArrayRef );
           use [Class::Tiny::ConstrainedAccessor](https://www.chedong.com/phpMan.php/perldoc/Class%3A%3ATiny%3A%3AConstrainedAccessor/markdown) {
             name     => Str,
             gender   => Str,
             age      => Num,
             children => ArrayRef,
           };
           use [Class::Tiny](https://www.chedong.com/phpMan.php/perldoc/Class%3A%3ATiny/markdown) qw( gender age ), {
             name     => sub { die "name is required"; },
             children => sub { return [] },
           };
         }

   [Class::Tiny::Antlers](https://www.chedong.com/phpMan.php/perldoc/Class%3A%3ATiny%3A%3AAntlers/markdown)
       [Class::Tiny::Antlers](https://www.chedong.com/phpMan.php/perldoc/Class%3A%3ATiny%3A%3AAntlers/markdown) provides Moose-like syntax for [Class::Tiny](https://www.chedong.com/phpMan.php/perldoc/Class%3A%3ATiny/markdown),
       including support for "isa".  You do not also need to use [Class::Tiny](https://www.chedong.com/phpMan.php/perldoc/Class%3A%3ATiny/markdown)
       itself.

         package Horse {
           use [Class::Tiny::Antlers](https://www.chedong.com/phpMan.php/perldoc/Class%3A%3ATiny%3A%3AAntlers/markdown) qw(has);
           use [Types::Standard](https://www.chedong.com/phpMan.php/perldoc/Types%3A%3AStandard/markdown) qw( Str Num ArrayRef );
           use [namespace::autoclean](https://www.chedong.com/phpMan.php/perldoc/namespace%3A%3Aautoclean/markdown);

           has name       => (
             is        => 'ro',
             isa       => Str,
             default   => sub { die "name is required" },
           );
           has gender     => ( is => 'ro',    isa => Str );
           has age        => ( is => 'rw',    isa => Num );
           has children   => (
             is        => 'ro',
             isa       => ArrayRef,
             default   => sub { return [] },
           );
         }

NEXT STEPS
       Here's your next step:

       o   [Type::Tiny::Manual::UsingWithOther](https://www.chedong.com/phpMan.php/perldoc/Type%3A%3ATiny%3A%3AManual%3A%3AUsingWithOther/markdown)

           Using [Type::Tiny](https://www.chedong.com/phpMan.php/perldoc/Type%3A%3ATiny/markdown) with [Class::InsideOut](https://www.chedong.com/phpMan.php/perldoc/Class%3A%3AInsideOut/markdown), [Params::Check](https://www.chedong.com/phpMan.php/perldoc/Params%3A%3ACheck/markdown), and
           [Object::Accessor](https://www.chedong.com/phpMan.php/perldoc/Object%3A%3AAccessor/markdown).

AUTHOR
       Toby Inkster <<tobyink@cpan.org>>.

COPYRIGHT AND LICENCE
       This software is copyright (c) 2013-2014, 2017-2021 by Toby Inkster.

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

DISCLAIMER OF WARRANTIES
       THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
       WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
       MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.

perl v5.32.1                      [2Type::Tiny::Manual](https://www.chedong.com/phpMan.php/perldoc/2Type%3A%3ATiny%3A%3AManual/markdown)::[UsingWithClassTiny(3pm)](https://www.chedong.com/phpMan.php/man/UsingWithClassTiny/3pm/markdown)
