App::Rad is in the same vein as App::Cmd but much simpler to use for some applications, as all your commands will fit in a single file.

But I'm hitting a wall, I need help. Here is an example of some commands I want to run (my application is called aid):

### Create some entries in various CSV tables # Maria is a person aid add person maria # HSBC is a bank aid add bank hsbc # Perlmonk is a website aid add website perlmonks ### List them all, and check for existence aid list person aid listed person maria ### Operations # There is £100 in maria's bank account aid set hsbc maria 100 # How much is there, again? aid get hsbc maria # £100 # Maria wrote 25 posts on Perlmonks aid set maria perlmonks 25 # How much? aid get maria perlmonks ### More to come...
It's pretty simple, right?

All of my commands are processing the two same arguments:

Because I need them for almost all commands, in all functions I keep on writing:

use Function::Parameters; # works with App::Rad, while Kavorka doesn't fun add ($c) { my ($data, $data_type) = @{_process_data($c)}; my ($name) = @{$c->argv}; $data->add($name); } # $data is a wrapper object to a csv file: person.csv / bank.csv / etc # This way I can delegate the work to these different entities # $data_type is not used here, but could be used to display a message
which is a pain (especially when most of my functions just call a method on an object), and not the ideal of maintainability. Any idea to relieve my pain?

I tried to use an around modifier, but it doesn't seem compatible:

use Class::Method::Modifiers; around 'add' => sub { my $orig = shift; my $c = shift; my ($data, $data_type) = @{_process_data($c)}; my ($name) = @{$c->argv}; $orig->($data, $data_type, $name, @_); }; sub add ($data, $data_type, $name) { $data->add($name); }
Notice how the add() code is much simplified. But it throws:
Can't locate object method "add" via package "App::Rad" at bin/arb-aid +.pl line 58. main::add('App::Rad=HASH(0xa20010)') called at /home/user/.per +lbrew/libs/perl-5.16.3@devel/lib/perl5/App/Rad/Command.pm line 251 App::Rad::Command::run('App::Rad::Command=HASH(0x1ac72c0)', 'A +pp::Rad=HASH(0xa20010)') called at /home/user/.perlbrew/libs/perl-5.1 +6.3@devel/lib/perl5/App/Rad.pm line 598 App::Rad::__ANON__('App::Rad=HASH(0xa20010)') called at /home/ +user/.perlbrew/libs/perl-5.16.3@devel/lib/perl5/App/Rad.pm line 321 App::Rad::_run_full_round('App::Rad=HASH(0xa20010)', 'CODE(0xa +34138)') called at /home/user/.perlbrew/libs/perl-5.16.3@devel/lib/pe +rl5/App/Rad.pm line 602 App::Rad::run('App::Rad') called at bin/arb-aid.pl line 2

So, for the maintainer of the quite awesome App::Rad, here is a feature request: Do you think you could make it compatible with method modifiers?

Otherwise, if anyone has an idea of something smarter I could do, please tell. I'm also eager for some honest critique, if my approach to this problem is wrong.


In reply to 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.