Added developer (perldoc) documentation.

This commit is contained in:
JT Smith 2002-08-07 02:14:20 +00:00
parent 593c1f3e59
commit bd0bf20710
4 changed files with 386 additions and 32 deletions

View file

@ -1,14 +1,18 @@
package WebGUI::DateTime;
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2002 Plain Black LLC.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
=head1 LEGAL
-------------------------------------------------------------------
WebGUI is Copyright 2001-2002 Plain Black LLC.
-------------------------------------------------------------------
Please read the legal notices (docs/legal.txt) and the license
(docs/license.txt) that came with this distribution before using
this software.
-------------------------------------------------------------------
http://www.plainblack.com info@plainblack.com
-------------------------------------------------------------------
=cut
use Date::Calc;
use Exporter;
@ -20,7 +24,67 @@ use WebGUI::Utility;
our @ISA = qw(Exporter);
our @EXPORT = qw(&localtime &time &addToTime &addToDate &epochToHuman &epochToSet &humanToEpoch &setToEpoch &monthStartEnd);
=head1 NAME
Package WebGUI::DateTime
=head1 SYNOPSIS
use WebGUI::DateTime;
$epoch = WebGUI::DateTime::addToDate($epoch, $years, $months, $days);
$epoch = WebGUI::DateTime::addToTime($epoch, $hours, $minutes, $seconds);
$dateString = WebGUI::DateTime::epochToHuman($epoch, $formatString);
$setString = WebGUI::DateTime::epochToSet($epoch);
$day = WebGUI::DateTime::getDayName($dayInteger);
$month = WebGUI::DateTime::getMonthName($monthInteger);
$epoch = WebGUI::DateTime::humanToEpoch($dateString);
$seconds = WebGUI::DateTime::intervalToSeconds($interval, $units);
@date = WebGUI::DateTime::localtime($epoch);
($startEpoch, $endEpoch) = WebGUI::DateTime::monthStartEnd($epoch);
($interval, $units) = WebGUI::DateTime::secondsToInterval($seconds);
$epoch = WebGUI::DateTime::setToEpoch($setString);
$epoch = WebGUI::DateTime::time();
=head1 DESCRIPTION
This package provides easy to use date math functions, which are
normally a complete pain.
=head1 METHODS
These functions are available from this package:
=cut
#-------------------------------------------------------------------
=head2 addToDate ( epoch [ , years, months, days ] )
Returns an epoch date with the amount of time added.
=item epoch
The number of seconds since January 1, 1970.
=item years
The number of years to add to the epoch.
=item months
The number of months to add to the epoch.
=item days
The number of days to add to the epoch.
=cut
sub addToDate {
my ($year,$month,$day, $hour,$min,$sec, $newDate);
($year,$month,$day, $hour,$min,$sec) = Date::Calc::Time_to_Date($_[0]);
@ -30,6 +94,29 @@ sub addToDate {
}
#-------------------------------------------------------------------
=head2 addToTime ( epoch [ , hours, minutes, seconds ] )
Returns an epoch date with the amount of time added.
=item epoch
The number of seconds since January 1, 1970.
=item hours
The number of hours to add to the epoch.
=item minutes
The number of minutes to add to the epoch.
=item seconds
The number of seconds to add to the epoch.
=cut
sub addToTime {
my ($year,$month,$day, $hour,$min,$sec, $newDate);
($year,$month,$day, $hour,$min,$sec) = Date::Calc::Time_to_Date($_[0]);
@ -39,6 +126,42 @@ sub addToTime {
}
#-------------------------------------------------------------------
=head2 epochToHuman ( [ epoch, format ] )
Returns a formated date string.
=item epoch
The number of seconds since January 1, 1970. Defaults to NOW!
=item format
A string representing the output format for the date. Defaults to
'%z %Z'. You can use the following to format your date string:
%% = % (percent) symbol.
%c = The calendar month name.
%d = A two digit day.
%D = A variable digit day.
%h = A two digit hour (on a 12 hour clock).
%H = A variable digit hour (on a 12 hour clock).
%j = A two digit hour (on a 24 hour clock).
%J = A variable digit hour (on a 24 hour clock).
%m = A two digit month.
%M = A variable digit month.
%n = A two digit minute.
%p = A lower-case am/pm.
%P = An upper-case AM/PM.
%s = A two digit second.
%w = The name of the week.
%y = A four digit year.
%Y = A two digit year.
%z = The current user's date format preference.
%Z = The current user's time format preference.
=cut
sub epochToHuman {
my ($offset, $temp, $hour12, $value, $output, @date, $day, $month);
$offset = $session{user}{timeOffset} || 0;
@ -106,11 +229,35 @@ sub epochToHuman {
}
#-------------------------------------------------------------------
=head2 epochToSet ( epoch )
Returns a set date (used by WebGUI::HTMLForm->date) in the format
of MM/DD/YYYY.
=item epoch
The number of seconds since January 1, 1970.
=cut
sub epochToSet {
return epochToHuman($_[0],"%m/%d/%y");
}
#-------------------------------------------------------------------
=head2 getMonthName ( month )
Returns a string containing the calendar month name in the language
of the current user.
=item month
An integer ranging from 1-12 representing the month.
=cut
sub getMonthName {
if ($_[0] == 1) {
return WebGUI::International::get(15);
@ -140,6 +287,19 @@ sub getMonthName {
}
#-------------------------------------------------------------------
=head2 getDayName ( day )
Returns a string containing the weekday name in the language of the
current user.
=item day
An integer ranging from 1-7 representing the day of the week (Sunday
is 1 and Saturday is 7).
=cut
sub getDayName {
if ($_[0] == 1) {
return WebGUI::International::get(27);
@ -159,7 +319,17 @@ sub getDayName {
}
#-------------------------------------------------------------------
# eg: humanToEpoch(YYYY-MM-DD HH:MM:SS)
=head2 humanToEpoch ( date )
Returns an epoch date derived from the human date.
=item date
The human date string. YYYY-MM-DD HH:MM:SS
=cut
sub humanToEpoch {
my (@temp, $dateString, $timeString, $output, @date);
($dateString,$timeString) = split(/ /,$_[0]);
@ -176,6 +346,22 @@ sub humanToEpoch {
}
#-------------------------------------------------------------------
=head2 intervalToSeconds ( interval, units )
Returns the number of seconds derived from the interval.
=item interval
An integer which represents the amount of time for the interval.
=item units
A string which represents the units of the interval. The string
must be 'years', 'months', 'days', 'hours', 'minutes', or 'seconds'.
=cut
sub intervalToSeconds {
if ($_[1] eq "years") {
return ($_[0]*31536000);
@ -195,11 +381,35 @@ sub intervalToSeconds {
}
#-------------------------------------------------------------------
=head2 localtime ( epoch )
Returns an array of time elements. The elements are: years, months,
days, hours, minutes, seconds, day of year, day of week, daylight
savings time.
=item epoch
The number of seconds since January 1, 1970.
=cut
sub localtime {
return Date::Calc::Localtime($_[0]);
}
#-------------------------------------------------------------------
=head2 monthStartEnd ( epoch )
Returns the epoch dates for the start and end of the month.
=item epoch
The number of seconds since January 1, 1970.
=cut
sub monthStartEnd {
my ($year,$month,$day, $hour,$min,$sec, $start, $end);
($year,$month,$day, $hour,$min,$sec) = Date::Calc::Time_to_Date($_[0]);
@ -210,6 +420,18 @@ sub monthStartEnd {
}
#-------------------------------------------------------------------
=head2 secondsToInterval ( seconds )
Returns an interval and units derived the number of seconds.
=item seconds
The number of seconds in the interval.
=cut
sub secondsToInterval {
my ($interval, $units);
if ($_[0] >= 31536000) {
@ -238,6 +460,17 @@ sub secondsToInterval {
}
#-------------------------------------------------------------------
=head2 setToEpoch ( set )
Returns an epoch date.
=item set
A string in the format of MM/DD/YYYY.
=cut
sub setToEpoch {
my @date = &localtime(time());
my ($month, $day, $year) = split(/\//,$_[0]);
@ -260,6 +493,13 @@ sub setToEpoch {
}
#-------------------------------------------------------------------
=head2 time ( )
Returns an epoch date.
=cut
sub time {
return Date::Calc::Mktime(Date::Calc::Today_and_Now());
}

View file

@ -1,14 +1,18 @@
package WebGUI::International;
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2002 Plain Black LLC.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
=head1 LEGAL
-------------------------------------------------------------------
WebGUI is Copyright 2001-2002 Plain Black LLC.
-------------------------------------------------------------------
Please read the legal notices (docs/legal.txt) and the license
(docs/license.txt) that came with this distribution before using
this software.
-------------------------------------------------------------------
http://www.plainblack.com info@plainblack.com
-------------------------------------------------------------------
=cut
use strict;
use WebGUI::Session;
@ -16,7 +20,53 @@ use WebGUI::SQL;
my %international;
=head1 NAME
Package WebGUI::International
=head1 SYNOPSIS
use WebGUI::International;
$string = WebGUI::International::get($internationalId,$namespace,$languageId);
%languages = WebGUI::International::getLanguages();
=head1 DESCRIPTION
This package provides an interface to the internationalization system.
=head1 FUNCTIONS
These functions are available from this package:
=cut
#-------------------------------------------------------------------
=head2 get ( internationalId [ , namespace, languageId ] )
Returns the internationalized message string for the user's language.
If there is no internationalized message, this method will
return the English string.
=item internationalId
An integer that relates to a message in the international table
in the WebGUI database.
=item namespace
A string that relates to the namespace field in the international
table in the WebGUI database. Defaults to 'WebGUI'.
=item languageId
An integer that specifies the language that the user should see.
Defaults to the user's defined language. If the user hasn't specified
a default language it defaults to '1' (English).
=cut
sub get {
my ($output, $language, $namespace);
if ($_[2] ne "") {
@ -34,7 +84,8 @@ sub get {
if (defined $international{$language}{$_[0]}) { # a little caching never hurts =)
$output = $international{$language}{$_[0]};
} else {
($output) = WebGUI::SQL->quickArray("select message from international where internationalId=$_[0] and namespace='$namespace' and languageId='$language'");
($output) = WebGUI::SQL->quickArray("select message from international
where internationalId=$_[0] and namespace='$namespace' and languageId='$language'");
if ($output eq "" && $language ne 1) {
$output = get($_[0],$namespace,1);
}
@ -43,6 +94,14 @@ sub get {
}
#-------------------------------------------------------------------
=head2 getLanguages ( )
Returns a hash reference to the languages (languageId/lanugage)
installed on this WebGUI system.
=cut
sub getLanguages {
my ($hashRef);
$hashRef = WebGUI::SQL->buildHashRef("select languageId,language from language");

View file

@ -1,23 +1,78 @@
package WebGUI::Mail;
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2002 Plain Black LLC.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
=head1 LEGAL
-------------------------------------------------------------------
WebGUI is Copyright 2001-2002 Plain Black LLC.
-------------------------------------------------------------------
Please read the legal notices (docs/legal.txt) and the license
(docs/license.txt) that came with this distribution before using
this software.
-------------------------------------------------------------------
http://www.plainblack.com info@plainblack.com
-------------------------------------------------------------------
=cut
use Net::SMTP;
use strict;
use WebGUI::ErrorHandler;
use WebGUI::Session;
=head1 NAME
Package WebGUI::Mail
=head1 SYNOPSIS
use WebGUI::Mail;
WebGUI::Mail::send($to,$subject,$message);
=head1 DESCRIPTION
This package provides access to use SMTP based email services.
=head1 METHODS
These methods are available from this class:
=cut
#-------------------------------------------------------------------
#eg: send("jt@jt.com","hi, how are you","this is my message","bob@bob.com","you@ther.com");
#eg: send(to,subject,message,cc,from,bcc);
=head2 send ( to, subject, message [ , cc, from, bcc ] )
Sends an SMTP email message to the specified user.
=item to
An email address for the TO line.
=item subject
The subject line for the email.
=item message
The message body for the email.
=item cc
The email address for the CC line.
=item from
The email address for the FROM line. Defaults to the email address
specified in the Company Settings.
=item bcc
The email address for the BCC line.
=cut
sub send {
my ($smtp, $message, $from);
$from = $_[4] || ($session{setting}{companyName}.' <'.$session{setting}{companyEmail}.'>');

View file

@ -46,7 +46,7 @@ use WebGUI::URL;
=head1 DESCRIPTION
This package proovides an object-oriented way of managing WebGUI
This package provides an object-oriented way of managing WebGUI
users as well as getting/setting a users's profile data.
=head1 METHODS