English::Reference - use words to dereference things


English-Reference documentation Contained in the English-Reference distribution.

Index


Code Index:

NAME

Top

English::Reference - use words to dereference things

SYNOPSIS

Top

  use English::Reference;
  or
  use English::Reference qw(deref);
  ...
  print SCALAR \"Hello World";

DESCRIPTION

Top

Provides the ability to use:

  ARRAY  $arrayref
  CODE   $coderef
  GLOB   $globref
  HASH   $hashref
  SCALAR $scalaref

en lieu of

  @$arrayref
  &$coderef
  *$globref
  %$hashref
  $$scalaref

or

  @{$arrayref}
  &{$coderef}
  *{$globref}
  %{$hashref}
  ${$scalaref}

As an added bonus, there is a function deref; not exported by default; which you can use to dereference a reference of any type.

CAVEATS

Top

You cannot do ARRAY{$arrayref} etc. This is not too bad seeing as the whole point of this module is to reduce the amount of punctuation you use.

AUTHORS

Top

Jerrad Pierce <belg4mit@mit.edu, the_lorax@usa.net>, Jeff Pinyan <japhy@pobox.com>, Casey R. Tweten <crt@kiski.net>

SEE ALSO

Top

English(3).


English-Reference documentation Contained in the English-Reference distribution.

package English::Reference;

use strict;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);

require Exporter;

@ISA = qw(Exporter);
# Items to export into callers namespace by default. Note: do not export
# names by default without a very good reason. Use EXPORT_OK instead.
# Do not simply export all your public functions/methods/constants.
@EXPORT = qw(
	     ARRAY CODE GLOB HASH SCALAR
	     );
@EXPORT_OK = qw(
	     deref
	     );

$VERSION = '0.01';

#bootstrap English::Reference $VERSION;

sub ARRAY($) {
    return @{ shift() };
}
sub CODE($) {
    return &{ shift() };
}
sub GLOB($) {
    return *{ shift() };
}
sub HASH($) {
    return %{ shift() };
}
sub SCALAR($) {
    return ${ shift() };
}

sub deref($) {
    no strict qw(refs);
    return &{ref($_[0])}($_[0]);
}

1;
__END__