Questions about distributing Dancer2 applications
I have a Dancer2 application that I'd like to distribute. I have a couple of questions about the process that may be more related to ExtUtils::MakeMaker than to Dancer, but I figured I'd ask here first since deployment of web applications seems a little different from installing regular modules. 1. Typically when you install a Perl package with perl Makefile.PL && make && make install modules goes somewhere like /usr/local/lib/perl5/, binaries go somewhere like /usr/local/bin/, documentation goes somewhere else, and so on. I don't want my application fragmented like that (and I don't think it would even work if it were); when users run `make install` I want everything from my MANIFEST to simply be copied into the install directory as-is. For example, I want to end up with /usr/local/myapp/bin/ /usr/local/myapp/lib/ /usr/local/myapp/lib/myapp.pm /usr/local/myapp/public/ ... I assume this is how most Dancer/Dancer2 apps would have to be installed to work properly...how can I do this? I tried perl Makefile.PL INSTALL_BASE=/usr/local/myapp/ but that puts myapp.pm in /usr/local/myapp/lib/perl5/ and doesn't copy any of the other files or directories I want, like public/. 2. My app includes an index page containing links to other pages on the same server, e.g. <a href="http://host.example.com/foo">foo</a> This page is served with send_file, no templates involved. So far I have simply hard-coded the server name into the file, but that won't work when somebody tries to install it on another server. I thought I could use the PL_FILES attribute to WriteMakefile() to run a script that fills in the correct host name during the build process. Would this be a reasonable approach?
Hi, I released a Dancer2 App too, so let me tell you what I think about the issues you're talking about. 1. In my opinion, releasing your app the way you want it's... well, not releasing it. I think that if your only need is to make users download your app and using it you should just make a tarball out of it and find a smart way to manage dependencies. Releasing your app (that is still releasing a perl module, at last) must involve your local repository and its paths because that's the essence of a release. Actualy there's no problem placing your app in a common @INC path and using it in a Dancer2 project. Your app is a perl module so, in your bin/app.pl, you can just import it with a use directive: #!/usr/bin/env perl use FindBin; use lib "$FindBin::Bin/../lib"; use Your::Released::App; Your::Released::App->dance; It's what I do here: https://github.com/cym0n/strehler/blob/master/src/lib/Strehler/Installation.... Ok, you'll need a bit of fine tuning about relative paths, but nothing impossibile to do. 2. Well, why hardcoding the server? Very few HTML magic is needed: <a href="/foo">foo</a> A brutal find and replace in your code putting the server name is, in my opinion, a very bad idea. If you need the explicit name in the pages just make it an entry in the config.yml and then write a little piece of code adding this entry in every template parameters hash. Talking about static elements and release question (as at 1.). If you realese "the real way" your app probably you statics elements (your public directory) will go in a very dark and gloomy place, difficult to be served by a webserver. For this, I suggest you to create a script that "sync" the public directory of the deployed app with the contents in your package. -- Cymon Coniglio domina, http://perlishscrewdriver.blogspot.com
I have a Dancer2 application that I'd like to distribute. I have a couple of questions about the process that may be more related to ExtUtils::MakeMaker than to Dancer, but I figured I'd ask here first since deployment of web applications seems a little different from installing regular modules.
1. Typically when you install a Perl package with
perl Makefile.PL && make && make install
modules goes somewhere like /usr/local/lib/perl5/, binaries go somewhere like /usr/local/bin/, documentation goes somewhere else, and so on. I don't want my application fragmented like that (and I don't think it would even work if it were); when users run `make install` I want everything from my MANIFEST to simply be copied into the install directory as-is. For example, I want to end up with
/usr/local/myapp/bin/ /usr/local/myapp/lib/ /usr/local/myapp/lib/myapp.pm /usr/local/myapp/public/ ...
I assume this is how most Dancer/Dancer2 apps would have to be installed to work properly...how can I do this? I tried
perl Makefile.PL INSTALL_BASE=/usr/local/myapp/
but that puts myapp.pm in /usr/local/myapp/lib/perl5/ and doesn't copy any of the other files or directories I want, like public/.
2. My app includes an index page containing links to other pages on the same server, e.g.
<a href="http://host.example.com/foo">foo</a>
This page is served with send_file, no templates involved. So far I have simply hard-coded the server name into the file, but that won't work when somebody tries to install it on another server.
I thought I could use the PL_FILES attribute to WriteMakefile() to run a script that fills in the correct host name during the build process. Would this be a reasonable approach? _______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
-- Cymon Coniglio domina, http://www.therabbit.it
On 05/06/2014 03:22 PM, Cymon wrote:
In my opinion, releasing your app the way you want it's... well, not releasing it. I think that if your only need is to make users download your app and using it you should just make a tarball out of it and find a smart way to manage dependencies.
Considering your answer to my second question, this is the route I'll go for now. `make tardist` and tell my users (read, co-workers) what dependencies to install.
Releasing your app (that is still releasing a perl module, at last) must involve your local repository and its paths because that's the essence of a release. Actualy there's no problem placing your app in a common @INC path and using it in a Dancer2 project. Your app is a perl module so, in your bin/app.pl, you can just import it with a use directive:
#!/usr/bin/env perl
use FindBin; use lib "$FindBin::Bin/../lib";
use Your::Released::App;
Your::Released::App->dance;
It's what I do here: https://github.com/cym0n/strehler/blob/master/src/lib/Strehler/Installation....
Ok, you'll need a bit of fine tuning about relative paths, but nothing impossibile to do.
This is good to know. I guess it makes sense that as long as the module is in @INC you can use it, no matter where app.pl is.
2.
Well, why hardcoding the server? Very few HTML magic is needed:
<a href="/foo">foo</a>
*facepalm* I knew that... Thank you, you've saved me from some horrific over-engineering.
A brutal find and replace in your code putting the server name is, in my opinion, a very bad idea. If you need the explicit name in the pages just make it an entry in the config.yml and then write a little piece of code adding this entry in every template parameters hash.
Talking about static elements and release question (as at 1.). If you realese "the real way" your app probably you statics elements (your public directory) will go in a very dark and gloomy place, difficult to be served by a webserver. For this, I suggest you to create a script that "sync" the public directory of the deployed app with the contents in your package.
Also helpful advice. Thank you very much.
participants (2)
-
Cymon -
Maxwell Carey