Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: RFC: Business::CreditCard::Obscure

by cees (Curate)
on Aug 21, 2006 at 19:42 UTC ( #568662=note: print w/ replies, xml ) Need Help??


in reply to RFC: Business::CreditCard::Obscure

This is a module that might benefit from Sub::Exporter. It allows you to export custom functions that are tailored to the user's needs. Here are some usage examples:

use Business::CreditCard::Obscure qw(obscure); print obscure('4444333322221111'); # 4444********1111 use Business::CreditCard::Obscure obscure => { head => 4, tail => -4, replacement => '!' }; print obscure('4444333322221111'); # 4444!!!!!!!!1111 use Business::CreditCard::Obscure obscure => { head => 4, -as => 'obscurevisa' }, obscure => { head => 3, tail => -3, -as => 'obscurediner' }; print obscurevisa('4444333322221111'); # 4444********1111 print obscurediner('444333222111'); # 444******111

And here is the code to implement the above examples:

package Business::CreditCard::Obscure; use strict; use warnings; use Sub::Exporter -setup => { exports => [ obscure => \&build_obscure ] }; sub build_obscure { my ( $class, $name, $arg ) = @_; $arg->{head} ||= 0; $arg->{tail} ||= -4; $arg->{replacement} ||= '*'; return sub { my $data = shift; substr( $data, $arg->{head}, $arg->{tail} ) =~ s/./$arg->{replacement}/g; return $data; } } 1;


Comment on Re: RFC: Business::CreditCard::Obscure
Select or Download Code
Replies are listed 'Best First'.
Re^2: RFC: Business::CreditCard::Obscure
by izut (Chaplain) on Aug 21, 2006 at 20:02 UTC

    That's what I was thinking about. Like:

    package Business::CreditCard::Obscure; sub new { ... } sub obscure { ... _obscure(%data); } sub _obscure { ... }

    Then exporting Business::CreditCard::Obscure::_obscure as obscure.

    Igor 'izut' Sutton
    your code, your rules.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://568662]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (18)
As of 2015-07-30 20:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (273 votes), past polls