| 1 | # -*- perl -*- | ||
| 2 | |||
| 3 | # Copyright (c) 2010 AdCopy | ||
| 4 | # Author: Jeff Weisberg | ||
| 5 | # Created: 2010-Jan-26 10:37 (EST) | ||
| 6 | # Function: connect user provided implementation | ||
| 7 | # | ||
| 8 | # $Id: Customize.pm,v 1.2 2010/09/07 15:31:53 jaw Exp $ | ||
| 9 | |||
| 10 | package AC::Yenta::Customize; | ||
| 11 | use strict; | ||
| 12 | |||
| 13 | sub customize { | ||
| 14 | my $class = shift; | ||
| 15 | my $implby = shift; | ||
| 16 | |||
| 17 | (my $default = $class) =~ s/(.*)::([^:]+)$/$1::Default::$2/; | ||
| 18 | |||
| 19 | # load user's implemantation + default | ||
| 20 | for my $p ($implby, $default){ | ||
| 21 | eval "require $p" if $p; | ||
| 22 | die $@ if $@; | ||
| 23 | } | ||
| 24 | |||
| 25 | # import/export | ||
| 26 | no strict; | ||
| 27 | no warnings; | ||
| 28 | for my $f ( @{$class . '::CUSTOM'} ){ | ||
| 29 | *{$class . '::' . $f} = ($implby && $implby->can($f)) || $default->can($f); | ||
| 30 | } | ||
| 31 | } | ||
| 32 | |||
| 33 | 1; |