Main Site Contents Up Previous Next

Path Functions

When packaged, your application is contained in a standard directory layout:

../MyTopFolder/bin
../MyTopFolder/dll
../MyTopFolder/lib
../MyTopFolder/res
../MyTopFolder/user

Or for a MacOSX App Bundle:

../MyTopFolder.app/Contents/MacOS
../MyTopFolder.app/Contents/Frameworks
../MyTopFolder.app/Contents/Resources/lib
../MyTopFolder.app/Contents/Resources/res
../MyTopFolder.app/Contents/Resources/user

The 'res' folder may not be present if you have chosen the compression option.

The Cava::Packager utilities provide access to path methods that mean you need not code for these differences.


Cava::Packager::GetBinPath();

In a packaged application, will return the folder path which contains the currently running executable. When running in development, will return the folder that your script is in. The exact relative location in a packaged distribution may vary on MS Windows if the executable is packaged in the root folder rather than the bin folder.


Cava::Packager::GetStandardBinPath();

In a packaged application, will always return the standard bin path. That is ../MyTopFolder/bin

When not packaged returns the folder that your script is in by default.

This function is only relevant on MS Windows where it is possible to package an executable in the root folder rather than the bin folder. This function always returns ../MyTopFolder/bin regardless of the location of the current executable.


Cava::Packager::SetStandardBinPath($path);

A convenience function. This is a no-op when packaged. Cava Packager provides the GetStandardBinPath function when packed that returns the path to your standard bin directory. This function allows you to provide defaults to your code if needed when running prior to packaging.


Cava::Packager::GetExePath();

Returns the full path to your executable, or at development time to your script. Note, that when packaged, both $^X and $0 will contain the path to your executable.


Cava::Packager::SetResourcePath($path);

Used in your Perl development environment to set the path to your resource folder. This allows you use the resource access functions at development time. In the packaged application, this is a no-op as the resource folder location is fixed when the application is run. See Including Resources.


Cava::Packager::GetResourcePath();

Returns the path to your resources.


Cava::Packager::GetResource($partialpath);

Returns the full path to a resource by concatenating the ResourcePath and the $partialpath;

Cava Packager also provides an importable short alias for this function.

use Cava::Packager qw( CRF );
my $filepath = CRF('relativepath/resource.doc');


Cava::Packager::SetUserPath($path);

Used in your Perl development environment to set the path to your user folder. This allows you use the access functions at development time. In the packaged application, this is a no-op as the user folder location is fixed when the application is run. See Including Resources.


Cava::Packager::GetUserPath();

Returns the path to your user folder.


Cava::Packager::GetUserFile($partialpath);

Returns the full path to a file in your user folder by concatenating the user folder path and the $partialpath;


Cava::Packager::GetTempDir();

Cava Packager provides you with a per instance temporary directory that is cleaned up at application or script exit. This function returns the temporary directory path.


Cava::Packager::GetTempFile($ext);

Returns a new unique temporary filename. Optionally, an extension may be provided that will be appended to the filename.


Cava::Packager::SetSharedLibraryPath($path);

A convenience function. This is a no-op when packaged. Cava Packager provides the GetSharedLibraryPath function when packed that returns the path to your dll directory. This function allows you to provide sensible defaults to your code if needed when running prior to packaging.


Cava::Packager::GetSharedLibraryPath();

Returns the path to the 'dll' directory in a packaged application. Will return whatever (if anything) has been passed to SetSharedLibraryPath when running unpackaged.


Cava::Packager::SetStandardIncPath($path);

A convenience function. This is a no-op when packaged. Cava Packager provides the GetStandardIncPath function when packed that returns the path to your standard @INC directory (if any). This function allows you to provide sensible defaults to your code if needed when running prior to packaging.


Cava::Packager::GetStandardIncPath();

Returns the path to the Standard @INC directory in a packaged application. Will return whatever (if anything) has been passed to SetStandardIncPath when running unpackaged.


Cava::Packager::SetAppRoot($path);

A convenience function. This is a no-op when packaged. Cava Packager provides the GetAppRoot function when packed that returns the path to your application root. This function allows you to provide sensible defaults to your code if needed when running prior to packaging.


Cava::Packager::GetAppRoot();

Returns the path to your application root. For standard application layout this would be:

../MyTopFolder

Or for a MacOSX App Bundle:

../MyTopFolder.app/Contents/Resources

This is useful to retrieve the location of folders you may have added using a post build script or similar.


Cross Platform Helper Functions

Cava Packager provides a small number of helper functions that provide commonly needed file system locations in a cross-platform way.

Cava::Packager::GetUserAppDataDir();

Returns the path to the standard user writable application data directory for the platform. You must append your own application directory to this path.

Cava::Packager::GetCommonAppDataDir();

Returns the path to the common application data directory for the platform. None administrator or root users do not normally have write permissions to this directory. You must append your own application directory to this path.

Cava::Packager::GetUserDocumentDir();

Returns the path to the standard user document directory for the platform.





Contents Up Previous Next


Cava Packager Copyright © 2006-2012 Mark Dootson