0

Probably a silly question, but how do I get the path to the /public folder in Dancer?

I want to store/read csv files under the public folder, but don't know if Dancer offers any convenience methods to get the base path to the public folder.

The error I get when trying to create a file by saying:

open(FILE, ">>", "myapp/public/file.csv") or die "$!";

is:

No such file or directory in /ur/share/perl5/Dancer/Handler.pm l. 98

I'm not sure why it's going to Handler.pm?

a7omiton
  • 1,597
  • 4
  • 34
  • 61

1 Answers1

2

My first answer is, don't do it that way...for two reasons:

  1. You're potentially opening up a security issue. What if somehow a hacker figures out a way to write to your environment files, change your passwords, etc.?
  2. You really want your /public files to be static, for version control, portability, etc.

That being said, if you really still want to do this, the public dir lives in config->{public}:

print "Public dir:".config->{public}."\n";

Source: http://search.cpan.org/~xsawyerx/Dancer-1.3110/lib/Dancer/Config.pm#public_%28directory%29

yahermann
  • 1,539
  • 1
  • 12
  • 33
  • Are you saying it's a concern to put these files under public folder? I'm not sure then where to put such files (CSV data files)? Would it be a good idea to put them under bin? I don't think lib would be a good place for it as that has all my modules. Or should I just create my own folder? – a7omiton Aug 18 '14 at 20:24
  • 1
    If the CSV data files contain specific content that you'd like to serve, I would just create route(s) for them... GET '/file/somefile' for one specific file, or if many different files then GET '/file/:filename' and then fetch param('filename'), clean it up to avoid any hack attempts. And yes if you want to store non-static files somewhere I would create my own separate folder (under myapp) and if you're using version control set it to ignore that folder (along with /logs, etc.). – yahermann Aug 18 '14 at 21:01