NAME
Padre::Util - Padre non-Wx Utility Functions
DESCRIPTION
The Padre::Util
package is a internal storage area for miscellaneous functions that aren't really Padre-specific that we want to throw somewhere convenient so they won't clog up task-specific packages.
All functions are exportable and documented for maintenance purposes, but except for in the Padre core distribution you are discouraged in the strongest possible terms from using these functions, as they may be moved, removed or changed at any time without notice.
FUNCTIONS
slurp
my $content = Padre::Util::slurp( $file );
if ( $content ) {
print $$content;
} else {
# Handle errors appropriately
}
This is a simple slurp implementation, provided as a convenience for internal Padre use when loading trivial unimportant files for which we don't need anything more robust.
All file reading is done with binmode
enabled, and data is returned by reference to avoid needless copying.
Returns the content of the file as a SCALAR reference if the file exists and can be read.
Returns false if loading of the file failed.
This function is only expected to be used in situations where the file should almost always exist, and thus the reason why reading the file failed isn't really important.
newline_type
my $type = Padre::Util::newline_type( $string );
Returns None
if there was not CR
or LF
in the file.
Returns UNIX
, Mac
or Windows
if only the appropriate newlines were found.
Returns Mixed
if line endings are mixed.
get_matches
Parameters:
The text in which we need to search
The regular expression
The offset within the text where we the last match started so the next forward match must start after this.
The offset within the text where we the last match ended so the next backward match must end before this.
backward bit (1 = search backward, 0 = search forward) - Optional. Defaults to 0.
_T
The _T
function is used for strings that you do not want to translate immediately, but you will be translating later (multiple times).
The only reason this function needs to exist at all is so that the translation tools can identify the string it refers to as something that needs to be translated.
Functionally, this function is just a direct pass-through with no effect.
share
If called without a parameter returns the share directory of Padre. If called with a parameter (e.g. Perl6
) returns the share directory of Padre::Plugin::Perl6. Uses File::ShareDir inside.
get_project_rcs
Given a project directory (see get_project_dir
), returns the project's Revision Control System (RCS
) by name. This can be either CVS
, SVN
or Git
. Returns undef
if none was found.
get_project_dir
Given a file it will try to locate the root directory of the given project. This is a temporary work around till we get full project support but it is used by some (SVK
) plug-ins.
parse_version
This is a clone of ExtUtils::MakeMaker parse_version
to prevent loading a bunch of other modules
my $version = Padre::Util::parse_version($file);
Parse a $file
and return what $VERSION
is set to by the first assignment. It will return the string "undef"
if it can't figure out what $VERSION
is. $VERSION
should be for all to see, so our $VERSION
or plain $VERSION
are okay, but my $VERSION
is not.
parse_version()
will try to use version
before checking for $VERSION
so the following will work.
$VERSION = qv(1.2.3);
COPYRIGHT
Copyright 2008-2010 The Padre development team as listed in Padre.pm.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.