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 valueHere 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?
In reply to Need help writting a Perl Module by vendion
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |