Class::Accessor::Classy - accessors with minimal inheritance


NAME

Class::Accessor::Classy - accessors with minimal inheritance

Back to Top


SYNOPSIS

  package YourPackage;
  use Class::Accessor::Classy;
    with qw(new);              # with a new() method
    ro qw(foo);                # read-only
    rw qw(bar);                # read-write
    rs baz => \ (my $set_baz); # read-only, plus a secret writer
    # alternatively:
    my $set_bip = rs 'bip';
    ro_c suitcase => 'red';    # read-only class data
    rw_c hat      => 'black';  # read-write class data
    rs_c socks    => \ (my $set_socks) => undef;
    # alternative secret writer syntax
    my $set_shoes = rs_c shoes => undef;
    # also class read-only:
    constant seven => 7;
    constant eight => this->seven + 1;
      no  Class::Accessor::Classy;
      # ^-- removes all of the syntax bits from your namespace
  package whatever;
  YourPackage->set_hat(undef);
  my $obj = YourPackage->new(foo => 4, bar => 2);
  # NOTE I'm thinking of deprecating the get_foo() usage
  warn "foo ", $obj->foo;
  YourPackage->$set_socks("tube");

Back to Top


Frontend

Unlike other class-modifying code, this is not designed to be inherited from. Instead, you simply use it and get an invisible subclass containing your accessors. If you use the 'no' syntax (to call unimport), you are left with a squeaky-clean namespace.

Back to Top


Utilities

This introspection stuff is unreliable -- don't use it.

find_accessors

  @attribs = Class::Accessor::Classy->find_accessors($class);

find_subclasses

  @classlist = Class::Accessor::Classy->find_subclasses($class);

Back to Top


Subclassable

Customized subclasses may override these methods to create a new kind of accessor generator.

NOTE

You do not subclass Class::Accessor::Classy to construct your objects.

If you are just creating MyObject, you are not inheriting any of these methods.

The rest of this documentation only pertains to you if you are trying to create something like Class::Accessor::Classy::MyWay.

notation:

Read these as: $CAC = 'Class::Accessor::Classy'; (or whatever subclass you're creating.)

exports

  my %exports = $CAC->exports;

import

  $CAC->import;

unimport

  $CAC->unimport;

create_package

Creates and returns the package in which the accessors will live. Also pushes the created accessor package into the caller's @ISA.

If it already exists, simply returns the cached value.

  my $package = $CAC->create_package(
    class => $caller,
    in    => $package, # optional
  );

install_sub

  $CAC->install_sub($class, $name, $subref, $note);

annotate

  $CAC->annotate($class, $name, $note);

get_notes

  my %notes = $CAC->get_notes;

make_standards

  $CAC->make_standards($class, @list);

_getter

Returns a compiled getter subref corresponding to whether or not the class has a '--get' method.

  $CAC->_getter($class, $item);

make_getters

  $CAC->make_getters($class, @list);

_setter

Returns a compiled setter subref corresponding to whether or not the class has a '--set' method.

  $CAC->_setter($class, $item);

make_setters

  $CAC->make_setters($class, @list);

make_immutable

Creates immutable (one-time-only) setters.

  CAC->make_immutable($class, @list);

make_secrets

  my @names = $CAC->make_secrets($class, @list);

make_aliases

  $CAC->make_aliases($class, @list);

do_eval

  my $subref = $package->do_eval($string, @checks);

Back to Top


List Accessors

make_array_method

  $CAC->make_array_method(
    class     => $class,
    item      => $name,
    functions => [@functions],
    secret    => $bool,
  );

If secret is true, will return the list of names.

_get_array_subs

  my %subs = $CAC->_get_array_subs($name);

Back to Top


Class Accessors

make_class_data

  $CAC->make_class_data($mode, $class, $key, $value);

If mode is 'rs', returns the secret setter name.

Back to Top


AUTHOR

Eric Wilhelm @ <ewilhelm at cpan dot org>

http://scratchcomputing.com/

Back to Top


BUGS

If you found this module on CPAN, please report any bugs or feature requests through the web interface at http://rt.cpan.org. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

If you pulled this development version from my /svn/, please contact me directly.

Back to Top


COPYRIGHT

Copyright (C) 2006-2007 Eric L. Wilhelm, All Rights Reserved.

Back to Top


NO WARRANTY

Absolutely, positively NO WARRANTY, neither express or implied, is offered with this software. You use this software at your own risk. In case of loss, no person or entity owes you anything whatseover. You have been warned.

Back to Top


LICENSE

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

Back to Top

 Class::Accessor::Classy - accessors with minimal inheritance