Hey::Common - Common functions used in other Hey::* modules
use Hey::Common; my $common = Hey::Common->new; my $money = $common->formatMoney(524.4); # will return string "524.40"
my $common = Hey::Common->new;
This function provides access to all of these following methods.
$data->{users} = $common->forceArray($data->{users});
The input can either be an array ref or non-array ref. The output will either be that same array ref, or the non-array ref as the only item in an array as a ref.
This is useful for items that might or might not be an array ref, but you are expecting an array ref.
$someRandomCode = $common->randomCode($lengthOfCodeRequested, $keyStringOfPermittedCharacters); $someRandomCode = $common->randomCode(); # defaults for length and key $someRandomCode = $common->randomCode(8); # choose a specific length, but default key $someRandomCode = $common->randomCode(12, 'abcdefg'); # choose a specific length and key
$lengthOfCodeRequested defaults to 16.
$keyStringOfPermittedCharacters defaults to 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'.
my $newCopyOfSomeHashRef = $common->deepCopy($someHashRef);
It makes a copy of a reference instead of making a reference to it. There's some usefulness there.
if ($common->isAffirmative('y')) { print "'y' is affirmative, so you'll see this."; } if ($common->isAffirmative('no')) { print "'no' is not affirmative, so you won't see this"; }
This checks to see if the value is affirmative.
Things that are affirmative are: 'y', 'yes', 't', 'true', or any true numerical value.
if ($common->isNegative('y')) { print "'y' is not negative, so you won't see this."; } if ($common->isNegative('no')) { print "'no' is negative, so you'll see this"; }
This checks to see if the value is negative.
Things that are negative are: 'n', 'no', 'f', 'false', any false numerical value (zero), or undef/null.
my @aListOfRecipientEmailAddresses = ('george@somewhere.com', 'ed@server.com', 'ralph@elsewhere.com'); my $contentOfEmailIncludingHeader = <<CONTENT; From: fred@someplace.com To: fred@someplace.com Subject: The email subject This is the email body area. Fill it full of useful email content. Thanks, Fred Someplace Inc. CONTENT $common->smtpClient({ Host => 'smtp.server.someplace.com', From => 'fred@someplace.com', To => \@aListOfRecipientEmailAddresses, Content => $contentOfEmailIncludingHeader });
'Host' is optional and defaults to 'localhost'. Of course, you would need to be able to send email through whatever host you specify.
'From' is a single email address that is used as the envelope address.
'To' can be a single email address or a list of email addresses as a scalar or an array ref.
'Content' is the content of the email, with header and body included.
my $money = 515.3; $money = $common->formatMoney($money);
$money is the non-formatted money amount. It will be returned as a formatted string, but with no currency symbol.
my $something = 'This is something that will be hashed.'; my $sha1Hash = $common->sha1($something);
$something is any value that you want hashed. It can be a binary value or a simple scalar.
$sha1Hash is a simple sha1 hex of whatever you passed in.
Dusty Wilson <module-Hey-Common@dusty.hey.nu>
Copyright (C) 2006 by Dusty Wilson, hey.nu Network Community Services
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.
10 POD Errors
The following errors were encountered while parsing the POD:
=cut found outside a pod block. Skipping to next block.
To install Hey::Common, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Hey::Common
CPAN shell
perl -MCPAN -e shell install Hey::Common
For more information on module installation, please visit the detailed CPAN module installation guide.