in reply to App::Rad is pretty rad for creating command line apps, but... (need help!)

G'day mascip,

Firstly, I'm unfamiliar with the App::Rad module so I can't provide any direct help.

If the author given in the documentation, garu, is the same as the garu on PerlMonks, he hasn't been here for 5 years. Your feature request will probably fall on deaf ears.

You could use the View/Report Bugs link from the documentation and add your feature request with Severity=Wishlist.

-- Ken

  • Comment on Re: App::Rad is pretty rad for creating command line apps, but... (need help!)

Replies are listed 'Best First'.
Re^2: App::Rad is pretty rad for creating command line apps, but... (need help!)
by mascip (Pilgrim) on Mar 29, 2014 at 10:03 UTC

    Cheers for the advice :)
    I have written to the author's email address (the @cpan.org one indicated in the documentation). If he doesn't answer within a week, I will try to reach him through RT.

      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!

        ++ for being so responsive. Impressive.

        Amazing, thank you Garu !! You are very responsive indeed :-)

        Here is what add() looks like now:

        fun add ($c) { my ($data, $name) = @{$c->stash}{qw/data name/}; $data->add($name); }

        Now that I'm more confident that App::Rad is what I need, I have printed the documentation (18 pages) and will read it all.
        I had tried to use setup() instead of preprocess... because I hadn't read the whole doc.