Wow, it's been a while - both here and in App::Rad!

First of all, thanks for using App::Rad. I've been meaning to rewrite it from scratch in a much saner/cleaner/expandable way but never got around to it. Still, I'm glad you found it useful!

As for your question, if you're doing the same thing in all your commands, you should know that, as documented, App::Rad will optionally read a "setup" sub every time your app starts. People have used this to setup DBI handles, reading configuration files and whatnot.

There is also the "pre_process" function, which is like a "before" hook in Moose (but for all commands), and you can use it to parse $c->argv *after* Rad knows the command it's going to run, and put some things on the stash (like $data and $name).

With the code you shared here, I think you could try something like:

fun pre_process ($c) { my ($data, $data_type) = @{_process_data($c)}; $c->stash->{data} = $data; $c->stash->{data_type} = $data_type; $c->stash->{name} = $c->argv->[0]; } fun add ($c) { $c->stash->{data}->add( $c->stash->{name} ); }

Not as pretty as you might have hoped, but still pretty straightforward, I think :)

Note that, if you need to behave differently on some commands, you can check $c->cmd to see the name of the current command from within pre_process().

I'll keep method modifiers (as well as subcommands, which is what you seem to be doing) in mind if I ever get to that rewrite. Meanwhile, I hope this helps!

Cheers!


In reply to Re^3: App::Rad is pretty rad for creating command line apps, but... (need help!) by garu
in thread App::Rad is pretty rad for creating command line apps, but... (need help!) by mascip

Title:
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, details, 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, summary, 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.