[Catalyst] Begginer's question about application structure
Martin Bendix
martinbendix at yahoo.co.uk
Tue Nov 23 07:47:36 GMT 2010
>
>From: Sir Robert Burbridge <rburbrid at cisco.com>
>To: The elegant MVC web framework <catalyst at lists.scsys.co.uk>
>Sent: Mon, 22 November, 2010 17:20:16
>Subject: Re: [Catalyst] Begginer's question about application structure
>
> I use DBIx::Class with multiple interfaces in the same app; this is the
> structure I've found most useful so far:
>
> ### the lib dir.
> lib/
>
> ### MyApp stores everything relevant to my app
> lib/MyApp
>
> ### "MyApp::Web" stores the web interface
> lib/MyApp/Web
> lib/MyApp/Web/Model
> lib/MyApp/Web/View
> lib/MyApp/Web/Controller
>
> ### HTML::FormHandler forms that are web-specific.
> lib/MyApp/Web/Form
>
> ### Stores db stuff for DBIx::Class.
> lib/MyApp/Schema/
>
> ### Normal DBIx::Class schema, results, and resultsets
> lib/MyApp/Schema/MyApp
> lib/MyApp/Schema/MyApp/Result
> lib/MyApp/Schema/MyApp/ResultSet
>
> ### Schema/Result and Schema/ResultSet contain things like Moose roles
> ### that I want to apply to multiple models, but that really only make
> ### sense in the context of this application.
> lib/MyApp/Schema/Result
> lib/MyApp/Schema/ResultSet
>
> ### A namespace for script based access to the app
> lib/MyApp/Script
> lib/MyApp/Script/User
> lib/MyApp/Script/User/Create.pm
> lib/MyApp/Script/Report
> lib/MyApp/Script/Report/Documentation.pm
>
> ### Libs specific to the CLI
> lib/MyApp/CLI
>
> ### Tests
> t
>
> ### Store
> t/lib
>
> A couple of notes:
>
> The contents of lib/MyApp/Script are scripts that use MooseX::GetOpt. I
> added a helper script in script/myapp_utils.pl that allows me to do this
> (this is mock output, but you get the idea). In the example below, it
> scans through the following namespaces in order: MyApp::Script,
> $ENV{MYAPP_SCRIPT_NAMESPACE}, CatalystX::Script, Catalyst::Script;
> looking for ::Schema::Loader.
>
> ### Run with no arguments
> $ ./script/myapp_utils.pl
> Available scripts:
>
> Report::Testing
> Report::Documentation
> Schema::Loader
> User::Create
> User::Modify
> ...
>
> $ ./script/myapp_utils.pl Schema::Loader
> An error has occurred: Required option missing: username
> usage: myapp_utils.pl [-?bdnpu] [long options...]
> -? --usage --help Prints this usage information.
> -u --usr --user --username A username with which to log into
> the db
> -p --pwd --pass --password A password with which to log into
> the db
> -b --db --dsn The DSN of the source database (e.g.
> "dbi:mysql:myapp")
> -d --dir --directory a directory into which to install
> the schema
> -n --namespace the path to a directory
>
> $ ./script/myapp_utils.pl Schema::Loader \
> --user ogopogo \
> --pass vonmugwumpus \
> --dsn dbi:mysql:my_db \
> --dir lib \
> --namespace MyApp::Schema::MyApp
>
> Creating schema ... done.
>
> $
>
> Web forms are stored in the path like Halifax::Web::Form::CD::Create
> (create a new CD from the script interface).
>
> FWIW =)
>
> -Sir
Hi,
Thanks for taking the time to put this information together. There is some very
useful advice and ideas in there which I will take on board. MooseX::GetOpt
looks very handy, and it's this sort of information - the tips and tricks of the
professionals if you like - that really help to advance the skills and knowledge
of others.
Regards,
Martin
More information about the Catalyst
mailing list