General.pm

Code Index:


#
# 	Sebastien.Letort@toulouse.inra.fr
#	Created: April 05, 2007
#	Last Updated: April 16, 2007
#

package General;

BEGIN
{
    use Exporter ();
    use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);

    # Si vous utilisez RCS/CVS, ceci serait preferable
    # le tout sur une seule ligne, pour MakeMaker
    $VERSION = do {my @r = (q$Rev: 86 $ =~ /\d+/g); sprintf "%d." . "%02d" x $#r, @r};

    @ISA         = qw(Exporter);
    @EXPORT      = qw(&TRUE &FALSE IsDefined);
    %EXPORT_TAGS = ();                           # ex. : TAG => [ qw!name1 name2! ],

    # vos variables globales a etre exporter vont ici,
    # ainsi que vos fonctions, si necessaire
    @EXPORT_OK = qw(&ShowDebug &GetDirectoryFile);
}

use Data::Dumper;

# les constantes
use constant TRUE  => 1;
use constant FALSE => 0;

#les fonctions generales

Procedure ShowDebug

        Title      :    ShowDebug
        Usage      :    ShowDebug( {deep=>$deep}, @a_args );
        Prerequiste:    none
        Procedure  :    print onto STDERR the name of the function where the function was called
                        depending on the deep parameter
                        with the filename and the line number of the current file.
                        Then it prints the list of arguments with Dumper.
        Args       :    $deep, an integer representing the deep of the call
                                must be >=1
                        @a_args, the list of arguments to print out.
        Error      :    none
        Globals    :    none
        
        Note       :    I used a hash ref to preserved compatibility with previous usage ShowDebug(@a_args)
sub ShowDebug
{
    my (@args) = @_;

    my $deep = 1;
    if (ref $args[0] eq 'HASH')
    {
        $rh_hash = shift @args;
        $deep    = $$rh_hash{deep};
    }

    my ($package, $file, $line) = caller();

    my $subroutine = (caller($deep))[3] || $package;
    print STDERR "In $subroutine ($file:$line) :\n", Data::Dumper->Dump([@args]);
}

Function IsDefined

        Title      :    IsDefined
        Usage      :    print "\$var n'est pas vide\n"  if( IsDefined( $var ) );
        Prerequiste:    only works with string, any ideas to enhaced with interger (!=0) is welcome
        Function   :    shortcut to know if a variable is defined and non empty
        Returns    :    1 if var is defined and non empty, 0 otherwise
        Args       :    $var, a variable that should contains a string.
        Error      :    none
        Globals    :    none
sub IsDefined
{
    my ($var) = @_;

    return (defined $var and $var ne '');
}

Function IsDefined

        Title      :    IsDefined
        Usage      :    print "\$var n'est pas vide\n"  if( IsDefined( $var ) );
        Prerequiste:    only works with string, any ideas to enhaced with interger (!=0) is welcome
        Function   :    shortcut to know if a variable is defined and non empty
        Returns    :    1 if var is defined and non empty, 0 otherwise
        Args       :    $var, a variable that should contains a string.
        Error      :    none
        Globals    :    none
sub GetDirectoryFile
{
    my ($file) = @_;

    my $abs_path = $INC{$file};
    use File::Basename;

    return (dirname($abs_path));
}

1;