Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
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
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 perusing the Monastery: (5)
As of 2014-08-30 14:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (293 votes), past polls