FAQ
Hi,

it's probably an awful question, but I could not figure out the rationale
behind the module Class::Accessor::Grouped. The concept of accessors I know
of, but I do not understand what this "group" thing is all about. Does
anybody know where I can find more information regarding this? Or maybe a
short explanation?

thanks wolfgang

Search Discussions

  • Peter Rabbitson at Nov 10, 2008 at 12:40 pm

    q wrote:
    Hi,

    it's probably an awful question, but I could not figure out the
    rationale behind the module Class::Accessor::Grouped. The concept of
    accessors I know of, but I do not understand what this "group" thing is
    all about. Does anybody know where I can find more information regarding
    this? Or maybe a short explanation?
    The following is lifted directly from the fine manual. Please be more
    specific about which part you don't understand.



    mk_group_accessors

    Arguments: $group, @fieldspec

    Returns: none

    Creates a set of accessors in a given group.

    $group is the name of the accessor group for the generated accessors;
    they will call get_$group($field) on get and set_$group($field, $value)
    on set.
  • Joel Bernstein at Nov 10, 2008 at 12:43 pm

    2008/11/10 q <quarky@quantentunnel.de>:
    it's probably an awful question, but I could not figure out the rationale
    behind the module Class::Accessor::Grouped. The concept of accessors I know
    of, but I do not understand what this "group" thing is all about. Does
    anybody know where I can find more information regarding this? Or maybe a
    short explanation?
    I think the Class::Accessor::Grouped POD makes it quite clear. If you
    use the "simple" group you get behaviour like Class::Accessor, where
    an accessor call hits get_simple($property) and a mutator call hits
    set_simple($property, $value). However you also have other option
    groups: "inherited", which gives behaviour similar to
    Class::Data::Accessor, and "component_class" which is specifically an
    accessor for package-names (set it, and the package is loaded before
    the property set).

    Not to be rude, but did you read the C::A::Grouped manual before
    asking this question? I just skimmed it to answer this question and it
    seems quite clear.

    /joel
  • Joel Bernstein at Nov 10, 2008 at 1:11 pm

    2008/11/10 Joel Bernstein <joel@fysh.org>:
    2008/11/10 q <quarky@quantentunnel.de>:
    it's probably an awful question, but I could not figure out the rationale
    behind the module Class::Accessor::Grouped. The concept of accessors I know
    of, but I do not understand what this "group" thing is all about. Does
    anybody know where I can find more information regarding this? Or maybe a
    short explanation?
    I think the Class::Accessor::Grouped POD makes it quite clear. If you
    use the "simple" group you get behaviour like Class::Accessor, where
    an accessor call hits get_simple($property) and a mutator call hits
    set_simple($property, $value). However you also have other option
    groups: "inherited", which gives behaviour similar to
    Class::Data::Accessor, and "component_class" which is specifically an
    accessor for package-names (set it, and the package is loaded before
    the property set).
    OK, it looks at though I'm not actually correct.

    I've hit on a sort of side detail of CAG, rather than its main
    purpose. The main idea is that you can separate attributes into
    groups, where each group has a similar set of behaviour required to
    happen on get/set action. In OO terms, these are "attribute
    metaclasses". Defining a group "foo" implies that the class will
    implement a method "get_foo" and a method "set_foo", which will
    encapsulate the group-specific behaviours. Each time a property in the
    "foo" group is accessed, the "get_foo" method will be called with the
    property name, and so on.

    If you skim the DBIC source you'll see how DBIC uses the 3 builtin
    groups, but also defines a couple of others ("column" and
    "inflated_column"). The point is, we're able to hook arbitrary
    behaviour onto the get or set actions for those attributes, and we're
    able to do this in such a way as to abstract the logic away from each
    individual accessor, so that it has only to be written once for each
    group of similar properties.

    Hope this clarifies, and I'm sure the maintainer will gratefully
    accept a documentation patch from you, in the hope that others don't
    suffer the same confusion as you did.

    /joel
  • Q at Nov 10, 2008 at 3:38 pm
    Hi,

    that was the bit that was missing for me while chewing on the docs. I am
    sometimes a bit slow on grasping these concepts. Anyway that was quite
    helpful.

    Thanks wolfgang
    The main idea is that you can separate attributes into
    groups, where each group has a similar set of behaviour required to
    happen on get/set action. In OO terms, these are "attribute
    metaclasses". Defining a group "foo" implies that the class will
    implement a method "get_foo" and a method "set_foo", which will
    encapsulate the group-specific behaviours. Each time a property in the
    "foo" group is accessed, the "get_foo" method will be called with the
    property name, and so on.
  • Matt S Trout at Nov 15, 2008 at 8:18 pm

    On Mon, Nov 10, 2008 at 04:38:38PM +0100, q wrote:
    Hi,

    that was the bit that was missing for me while chewing on the docs. I am
    sometimes a bit slow on grasping these concepts. Anyway that was quite
    helpful.
    Please do try and write this up in such a way that it makes sense to you and
    send it on to Chris Laco (the C::A::G maintainer).

    C::A::G was originally DBIx::Class::AccessorGroup and while the documentaiton
    written when it was extracted describes the methods clearly I think everybody
    involved was already pretty clear on the purpose due to DBIC's column
    and inflated_column groups.

    --
    Matt S Trout Need help with your Catalyst or DBIx::Class project?
    Technical Director http://www.shadowcat.co.uk/catalyst/
    Shadowcat Systems Ltd. Want a managed development or deployment platform?
    http://chainsawblues.vox.com/ http://www.shadowcat.co.uk/servers/

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupdbix-class @
categoriesperl, catalyst
postedNov 10, '08 at 12:19p
activeNov 15, '08 at 8:18p
posts6
users4
websitedbix-class.org
irc#dbix-class

People

Translate

site design / logo © 2021 Grokbase