[Catalyst] myapp_test.pl - running code from the command line

Eden Cardim edencardim at gmail.com
Wed Nov 3 13:08:55 GMT 2010


>>>>> "Jonathon" == Jonathon Soong <jon at investmentscience.com.au> writes:

    Jonathon> Yes I realise now it might make more sense in the Model,
    Jonathon> but at the moment it is in the Controller (it is someone
    Jonathon> else's code, so more difficult for me to refactor).

That's barely an excuse, if you can run the code, you can read the code,
and if you can read the code, you can at least copy it into a model and
drop the usage of the original controller, unless there are legal
constraints in place which forbid that specific practice.

    Jonathon> There are two questions I have then: 1. How do you call a
    Jonathon> Model's function from the command line?  2. Is there no
    Jonathon> way to call controller methods that require
    Jonathon> authentication?

for the model case, you can

use MyApp;
MyApp->model('Foo')->bar;

for the authentication case, you're very probably relying on the
authentication API inside the controller code, which for most cases
won't work at all in a non-web environment. You'd have to mimic the
entire environment, which is a lot more trouble than just factoring your
code correctly.

-- 
   Eden Cardim       Need help with your Catalyst or DBIx::Class project?
  Code Monkey                    http://www.shadowcat.co.uk/catalyst/
 Shadowcat Systems Ltd.  Want a managed development or deployment platform?
http://blog.edencardim.com/            http://www.shadowcat.co.uk/servers/



More information about the Catalyst mailing list