Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Hi Monks,

I have a lot (30 94 and growing) of MooseX::Getopt based scripts inheriting from a single role (My::App). My::App includes quite a few getopt-enabled switches which don't make sense in some of the scripts which inherit from it. The result is that when the user runs script --help, they get a page and a half of options which are irrelevant.

I can suppress some options from a script by adding following to the attribute declarations in the inheriting script:

has( "+$_", traits => ['NoGetopt'] ) for qw<fast_db html_output japane +se_wts debug_soap lease_tolerance>;

This is effective, but not pretty, and since I have so many classes which use it, it would be nice to put it into a sub in a shared package. My::App seems like the logical choice, but:

has '+attr' is not supported in roles ...

Which is fine with me, but I'm calling this in a class, it's just that Moose thinks I'm calling it in a role. has isn't a method, so I can't use my package to tell Moose that it's being called from a role. It looks like has is using caller to see where it's being called from.

So what do people suggest? Should I:

  1. Put the 'disable_getopt_attribute' code in a different (new) package (which will probably never contain anything else)
  2. Try to work out how to trick has into running in a role
  3. Cut and paste the ugly code in all my classes

What do you think?

Update Much more than 30

- Boldra

In reply to MooseX::GetOpt disable in role by Boldra

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and a kettle whistles...

    How do I use this? | Other CB clients
    Other Users?
    Others browsing the Monastery: (7)
    As of 2018-02-20 09:58 GMT
    Find Nodes?
      Voting Booth?
      When it is dark outside I am happiest to see ...

      Results (268 votes). Check out past polls.