vendion has asked for the wisdom of the Perl Monks concerning the following question:

I am working on my first Perl module and I have quite a bit of questions about the process. I have read the tutorials and other nodes about it here on Perl Monks, as well as others from a Google search. The error that I get is:

core.pm did not return a true value

Here is my current working code, and before someone says anything about the lack of POD this module will never make it into CPAN it is a module for a personal project.

# Copyright 2009-2010 Adam Jimerson. All rights reserved # Use of this source code is governed by a BSD-style # license that can be found in the LICENSE.txt file package core; use warnings; use strict; use Carp; use Readonly; use English qw( -no_match_vars ); use DBI; require Exporter; our @ISA = qw(Exporter); our @EXPORT = (); our @EXPORT_OK = qw(); my $dbh = q[]; =head1 NAME core - The great new core! =head1 VERSION Version 0.01 =cut use version 0.77; our $VERSION = qv("v0.01"); BEGIN { #Added for Windows compatability, some ports of Perl (Active Perl, Str +awberry Perl, etc) on Windows #act differently when it comes to using Enviremental data "$ENV{}" if ( $^O =~ /MSWin32/ ) { if ( !$ENV{HOME} ) { if ( $ENV{USERPROFILE} ) { $ENV{HOME} = $ENV{USERPROFILE}; } elsif ( $ENV{HOMEDRIVE} and $ENV{HOMEPATH} ) { $ENV{HOME} = $ENV{HOMEDRIVE} . $ENV{HOMEPATH}; } else { croak "Can't set $ENV data, maybe check your install?\n"; } } } } #Open the Log file my ($date) = get_time('date'); my $logfile = q[]; if ( $^O =~ /MSWin32/ ) { $logfile = $ENV{HOME} . '\TickIt\Logs\\' . "$date.txt"; } else { $logfile = "$ENV{HOME}/TickIt/Logs/$date.txt"; } open my $LOG, '>>', $logfile || croak "Error: Can not open \'$logfile\': $OS_ERROR\n"; my ($time) = get_time('time'); print $LOG "[$time] INFO: Using Core $VERSION\n"; sub db_connect { # Check the status of the database connection, if none exists then cre +ate a new connection Readonly my $DATABASE => q[Repairs]; #Specify the database to be u +sed Readonly my $HOSTNAME => q[localhost]; Readonly my $PORT => q[5432]; #PostgreSQL port Readonly my $USER => q[user]; #PostgreSQL username Readonly my $PASSWORD => q[password]; #PostgreSQL password my $db_connected = q[0]; my $dsn = q[]; if ( $db_connected == 1 ) { return; } else { $dsn = "DBI:Pg:dbname=$DATABASE;host=$HOSTNAME;port=$PORT"; my $dbh = DBI->connect( $dsn, $USER, $PASSWORD, { AutoCommit => 1, RaiseError => 0 } ); if ($DBI::errstr) { my ($time) = get_time('time'); print $LOG "[$time] Couldn't authenticate to the Database: $DBI::er +rstr\n"; croak "Couldn't authenticate to the Database: $DBI::errstr\n"; } $db_connected++; } return; } sub clear_screen { # Clears the screen for both Windows and *nix systems and returns to +the caller if ( $^O =~ /MSWin32/ ) { system 'cls'; } else { system 'clear'; } return; } sub display_menu_error { # if any error messages are passed display them to the user and return + to the main menu my $msg = shift; my ($time) = get_time('time'); print $LOG "[$time] ERROR: $msg\n"; clear_screen(); print "$msg\n\n"; return; } sub process_input { # takes in information and loops through testing the input for valid a +lphanumeric characters my @data = @_; for (@data) { chomp; s/^\s*//; s/\s*$//; } return @data; } sub tech_login { #Start tech login section #Use the Student ID # print 'Please scan barcode to login: '; my $techID = <>; ($techID) = process_input($techID); my $sth = $dbh->prepare('SELECT * FROM tech WHERE id = ?'); $sth->execute($techID); my $tech_details = $sth->fetchrow_hashref(); if ( $tech_details eq q[] ) { display_menu_error("ERROR: Ether invalid ID or no tech found in the +system!"); } print "Welcome $tech_details->{firstname} $tech_details->{lastname}\n +"; print "ID: $tech_details->{id}\n"; if ( $techID eq '99' ) { print "\nWarning: You are loged in under \"Oh Shit\" mode!\n"; } print "Press Enter To Continue\n"; <>; #End tech login section return $techID; } sub get_barcode { # Gets the barcode information and returns to the calling function clear_screen(); print 'Please Scan System Barcode: '; # Get barcode information my $barcode = <>; ($barcode) = process_input($barcode); return $barcode; } sub get_time { # Gets the time from the OS and returns it to the caller my $value = shift; my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) = localtime time; $year += 1900; my @month_abbr = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec +); if ( $value eq 'date' ) { my $date = "$month_abbr[$mon]-$mday-$year"; return $date; } elsif ( $value eq 'time' ) { my $time = "$hour:$min:$sec"; return $time; } else { croak "ERROR: No value sent for time retreval!\n"; } } =head1 AUTHOR Adam Jimerson, C<< <vendion at vendion.net> >> =head1 BUGS Bugs?!?! There are no bugs in this software, but if you think you fou +nd one anyways send me an email with details on how to reproduce the +"bug" along with the correct log file. 1; # End of core

Can someone here help point out what I am doing wrong?

Replies are listed 'Best First'.
Re: Need help writting a Perl Module
by Anonyrnous Monk (Hermit) on Dec 08, 2010 at 20:21 UTC
    core.pm did not return a true value

    Put =cut before the 1 at the end:

    ... =cut 1;

    As you have it, the 1 is considered part of the POD.

Re: Need help writting a Perl Module
by roboticus (Chancellor) on Dec 08, 2010 at 20:23 UTC

    vendion:

    You forgot to end your final POD block. Add:

    =cut
    just before 1; #End of core to terminate the POD block and turn that line back into code. Then your module will return a true value for you.

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Re: Need help writting a Perl Module
by vendion (Scribe) on Dec 08, 2010 at 20:42 UTC

    Thanks that was kind of an obvious problem don't know how I could have over looked it... another question I have that I don't quite understand when I need to export information back to the script from the module do I need to give @EXPORT and @EXPORT_OK the name of the variable or the subroutine?

      do I need to give @EXPORT and @EXPORT_OK the name of the variable or the subroutine?

      If I'm understanding you correctly, your question is whether you need to specify the same variable/subroutine in both the @EXPORT and the @EXPORT_OK array (?) If so, no, put it in either one of them.

      @EXPORT_OK is for stuff to be exported upon request, i.e. when the user writes use Module qw(foo); while @EXPORT is for what should be exported by default (without explicit request), i.e. when the user simply says use Module;. If undesired, those default exports have to be disabled by writing use Module (); - note the (empty) list.

      P.S.

      require Exporter; our @ISA = qw(Exporter);

      can also be written as

      use Exporter 'import';

      (see also Re: Advice on style)

      Depends on want you want to do ... if you want the subs from your module shared with other scripts export the sube. If you want to share also variables e.g. constants, export the variables. Maybe better declare vars with 'our' then, I'm not sure if this is always necessary.

      Thank you both for answering my question