a7omiton
a7omiton

Reputation: 1617

How to get the public path in Perl Dancer

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?

Upvotes: 0

Views: 462

Answers (1)

yahermann
yahermann

Reputation: 1569

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

Upvotes: 2

Related Questions