The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Hey::Common - Common functions used in other Hey::* modules

SYNOPSIS

  use Hey::Common;
  my $common = Hey::Common->new;
  
  my $money = $common->formatMoney(524.4);  # will return string "524.40"

DESCRIPTION

new

  my $common = Hey::Common->new;

This function provides access to all of these following methods.

forceArray

  $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.

randomCode

  $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'.

deepCopy

  my $newCopyOfSomeHashRef = $common->deepCopy($someHashRef);

It makes a copy of a reference instead of making a reference to it. There's some usefulness there.

isAffirmative

  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.

isNegative

  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.

smtpClient

  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.

formatMoney

  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.

sha1

  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.

AUTHOR

Dusty Wilson <module-Hey-Common@dusty.hey.nu>

COPYRIGHT AND LICENSE

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:

Around line 5:

=cut found outside a pod block. Skipping to next block.

Around line 35:

=cut found outside a pod block. Skipping to next block.

Around line 60:

=cut found outside a pod block. Skipping to next block.

Around line 87:

=cut found outside a pod block. Skipping to next block.

Around line 109:

=cut found outside a pod block. Skipping to next block.

Around line 143:

=cut found outside a pod block. Skipping to next block.

Around line 180:

=cut found outside a pod block. Skipping to next block.

Around line 233:

=cut found outside a pod block. Skipping to next block.

Around line 260:

=cut found outside a pod block. Skipping to next block.

Around line 280:

=cut found outside a pod block. Skipping to next block.