The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.


Class::Accessor::Assert - Accessors which type-check


  use Class::Accessor::Assert;
  __PACKAGE__->mk_accessors( qw( +foo bar=Some::Class baz @bits ) );


This is a version of Class::Accessor which offers rudimentary type-checking and existence-checking of arguments to constructors and set accessors.

To specify that a member is mandatory in the constructor, prefix its name with a +. To specify that it needs to be of a certain class when setting that member, suffix =CLASSNAME. Unblessed reference types such as =HASH or =ARRAY are acceptable.

To specify that a member is an array, prefix its name with a @. These members also have the following four special methods that wrap the builtin array operations push, pop, unshift, and shift:

    # for a @bits member:
    print $y->bits_pop;
    print $y->bits_shift;

The @ can be combined with the + prefix to make a member that is an array that you must set in the constructor. The + must precede the @.

    # 'foo' is required in the constructor
    __PACKAGE__->mk_accessors(qw( +@foo ));




This module is maintained by

  Steffen Mueller, accessor-module at steffen-mueller dot net

Original author is

  Simon Cozens,

Please direct inquiries, bug reports, etc. towards the maintainer, not the original author. Simon no longer provides support for this module, so please respect that.


Copyright 2003 by Simon Cozens

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