NAME MooseX::Prototype - use an existing object as the template for a class SYNOPSIS { package Person; use Moose; has name => (is => 'rw', isa => 'Str'); has employer => (is => 'rw', isa => 'Str'); } package main; use MooseX::Prototype qw(use_as_prototype); my $template = Person->new(employer => 'Government'); my $CivilServant = use_as_prototype($template); my $bob = $CivilServant->new(name => 'Bob'); say $bob->name; # Bob say $bob->employer; # Government DESCRIPTION "use_as_prototype($object)" Given a blessed object (must be from a Moose-based class), the "use_as_prototype" function generates a new class such that: * the new class is a subclass of the class the original object was blessed into. * all methods available on the original object will be available to instances of the new class. * all attributes available on the original object will be available to instances of the new class, and the defaults for those attributes will reflect the values those attributes had on the original object. In short, it acts like a "clone" method might, but rather than returning a single cloned object, returns a class of clones. The class name used is not necessarily very nice - it will be along the lines of "MooseX::Prototype::__ANON__::0007". You can provide your own class name as a second parameter: my $template = Person->new(employer => 'Government'); use_as_prototype($template, 'CivilServant'); my $bob = CivilServant->new(name => 'Bob'); BUGS Please report any bugs to . SEE ALSO Object::Prototype, MooseX::Prototype::Role::UseAsPrototype. AUTHOR Toby Inkster . COPYRIGHT AND LICENCE This software is copyright (c) 2012 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.