MooseX::ClassAttribute: read-only outside, writable inside

Discussion in 'Perl Misc' started by Tim McDaniel, Apr 9, 2009.

  1. Tim McDaniel

    Tim McDaniel Guest

    I'm very new to Moose, and I'm probably missing something very simple.

    Does anyone have examples of code that
    - provides a class attribute via MooseX::ClassAttribute
    - that class attribute is readable but not changable by the outside
    world
    - that class attribute can be changed within the package itself?

    In my case, I have a class of objects that each have an integer key
    (set once at new() time, never changed thereafter). I'd like to
    provide to the user of the class a way to get the minimum key so far
    and the maximum key so far, but I don't want them to be able to change
    it. Within the package, though, I need to conditionally update max
    and min at every object creation (currently, I'm using "sub BUILD" to
    catch the event).

    I have a basic notion of how to do it outside Moose, but I'd like to
    do it "the usual Moose|MooseX way", especially as they may handle
    grungy details that I know nothing about, such as correct inheritance.

    --
    Tim McDaniel,
     
    Tim McDaniel, Apr 9, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. keithb
    Replies:
    2
    Views:
    8,072
    keithb
    Jun 7, 2006
  2. Bill Sneddon
    Replies:
    3
    Views:
    643
    Bill Sneddon
    Dec 24, 2003
  3. Andrew James
    Replies:
    1
    Views:
    1,006
    Diez B. Roggisch
    Dec 4, 2004
  4. Tomás Ó hÉilidhe

    Read-only outside translation unit

    Tomás Ó hÉilidhe, Dec 8, 2007, in forum: C Programming
    Replies:
    4
    Views:
    332
    Eric Sosman
    Dec 8, 2007
  5. Krzysztof Poc

    outside type, outside function

    Krzysztof Poc, Feb 3, 2012, in forum: C++
    Replies:
    1
    Views:
    314
    Victor Bazarov
    Feb 7, 2012
Loading...

Share This Page