logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

Class::Accessor::Class - simple class variable accessors

Author

       Ricardo SIGNES <rjbs@semiotic.systems>

Description

       Class::Accessor::Class provides a simple way to create accessor and mutator methods for class variables,
       just as Class::Accessor provides for objects.  It can use either an enclosed lexical variable, or a
       package variable.

       This module was once implemented in terms of Class::Accessor, but changes to that module broke this
       relationship.  Class::Accessor::Class is still a subclass of Class::Accessor, strictly for historical
       reasons.  As a side benefit, a class that isa Class::Accessor::Class is also a Class::Accessor and can
       use its methods.

Details

make_class_accessor
        $accessor = Class->make_class_accessor($field);

       This method generates a subroutine reference which acts as an accessor for the named field.

   make_package_accessor
        $accessor = Class->make_package_accessor($field);

       This method generates a subroutine reference which acts as an accessor for the named field, which is
       stored in the scalar named "field" in "Class"'s symbol table.

       This can be useful for dealing with legacy code, but using package variables is almost never a good idea
       for new code.  Use this with care.

Methods

mk_class_accessors
        package Foo;
        use base qw(Class::Accessor::Class);
        Foo->mk_class_accessors(qw(foo bar baz));

        Foo->foo(10);
        my $obj = new Foo;
        print $obj->foo;   # 10

       This method adds accessors for the named class variables.  The accessor will get or set a lexical
       variable to which the accessor is the only access.

   mk_package_accessors
        package Foo;
        use base qw(Class::Accessor::Class);
        Foo->mk_package_accessors(qw(foo bar baz));

        Foo->foo(10);
        my $obj = new Foo;
        print $obj->foo;   # 10
        print $Foo::foo;    # 10

       This method adds accessors for the named class variables.  The accessor will get or set the named
       variable in the package's symbol table.

Name

       Class::Accessor::Class - simple class variable accessors

Perl Version Support

       This code is effectively abandonware.  Although releases will sometimes be made to update contact info or
       to fix packaging flaws, bug reports will mostly be ignored.  Feature requests are even more likely to be
       ignored.  (If someone takes up maintenance of this code, they will presumably remove this notice.)

Synopsis

       Set up a module with class accessors:

        package Text::Fortune;

        use base qw(Class::Accessor::Class Exporter);
        Robot->mk_class_accessors(qw(language offensive collection));

        sub fortune {
          if (__PACKAGE__->offensive) {
                ..

       Then, when using the module:

        use Text::Fortune;

        Text::Fortune->offensive(1);

        print fortune; # prints an offensive fortune

        Text::Fortune->language('EO');

        print fortune; # prints an offensive fortune in Esperanto

Version

       version 0.504

See Also