Acme-VerySign

 view release on metacpan or  search on metacpan

lib/Acme/VerySign.pm  view on Meta::CPAN

package Acme::VerySign;

use overload '""' => "as_string",
    fallback => 1;

use Carp;
use Devel::Symdump;

use strict;
#use warnings;

use vars qw($AUTOLOAD $VERSION);

$VERSION = "1.00";

####################################################################
# cargo culted from Symbol::Approx::Sub
####################################################################

# List of functions that we _never_ try to match approximately.
my @_BARRED = qw(AUTOLOAD BEGIN CHECK INIT DESTROY END);
my %_BARRED = (1) x @_BARRED;

sub _pkg2file {
  $_ = shift;
  s|::|/|g;
  "$_.pm";
}

####################################################################

sub import
{
  my $class = shift;

  # work out who called us
  my $pkg =  caller(0);

  # turn off refs while we write to another package namespace
  no strict "refs";

  ####################################################################
  # cargo culted from Symbol::Approx::Sub
  ####################################################################

  my %param;
  my %CONF;
  %param = @_ if @_;

  my %defaults = (xform => 'Text::Soundex',
                  match => 'String::Equal',
                  choose => 'Random');

  # Work out which transformer(s) to use. The valid options are:
  # 1/ $param{xform} doesn't exist. Use default transformer.
  # 2/ $param{xform} is undef. Use no transformers.
  # 3/ $param{xform} is a reference to a subroutine. Use the 
  #    referenced subroutine as the transformer.
  # 4/ $param{xform} is a scalar. This is the name of a transformer
  #    module which should be loaded.
  # 5/ $param{xform} is a reference to an array. Each element of the
  #    array is one of the previous two options.

  if (exists $param{xform}) {
    if (defined $param{xform}) {
      my $type = ref $param{xform};
      if ($type eq 'CODE') {
        $CONF{xform} = [$param{xform}];
      } elsif ($type eq '') {
        my $mod = "Symbol::Approx::Sub::$param{xform}";
        require(_pkg2file($mod));
        $CONF{xform} = [\&{"${mod}::transform"}];
      } elsif ($type eq 'ARRAY') {
        foreach (@{$param{xform}}) {
          my $type = ref $_;
          if ($type eq 'CODE') {
            push @{$CONF{xform}}, $_;
          } elsif ($type eq '') {
            my $mod = "Symbol::Approx::Sub::$_";
            require(_pkg2file($mod));
            push @{$CONF{xform}}, \&{"${mod}::transform"};
          } else {
            croak 'Invalid transformer passed to Acme::VerySign';
          }
        }
      } else {
        croak 'Invalid transformer passed to Acme::VerySign';
      }
    } else {
      $CONF{xform} = [];
    }
  } else {
    my $mod = "Symbol::Approx::Sub::$defaults{xform}";
    require(_pkg2file($mod));
    $CONF{xform} = [\&{"${mod}::transform"}];
  }



( run in 2.034 seconds using v1.01-cache-2.11-cpan-437f7b0c052 )