Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: RFC: Business::CreditCard::Obscure

by izut (Chaplain)
on Aug 21, 2006 at 18:11 UTC ( #568631=note: print w/replies, xml ) Need Help??

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

I think you're not following OOP too close. I would change it to something like this (untested):

sub new { my ($class, %parameters) = @_; my $self = {}; # here we check required parameters, to croak() them. since we are + using # OOP, we *need* to ensure this object will be complete to perform + whatever # operations, avoiding coupling. foreach (qw(cardnum)) { # maybe we have other required parameters croak "Required parameter '$_' not found" unless exists $parameters{$_}; } # now we set defaults for not obligatory parameters $self->{'tail'} = $parameters{'tail'} || -4; $self->{'head'} = $parameters{'head'} || 0; $self->{'replacement'} = $parameters{'replacement'} || "*"; } sub obscure { my ($self) = @_; my $obscured = substr($self->{'cardnum'}, $self->{'head'}, $self->{'tail'} ) =~ s/./$self->{'replacement'}/g; return $obscured; }

Hope this helps.

Igor 'izut' Sutton
your code, your rules.

Replies are listed 'Best First'.
Re^2: RFC: Business::CreditCard::Obscure
by kwaping (Priest) on Aug 21, 2006 at 18:16 UTC
    I understand what you're saying and appreciate the comment. There is something you may be overlooking, though. I would like the user to have the choice of either calling new then obscure, or just going straight to Business::CreditCard::Obscure->obscure(). That's why I have the extra goodies inside that method. The constructor stuff in the new method was mostly just for user convenience to suit their preferred coding style. I'm aiming for maximum effective flexibility.

    It's all fine and dandy until someone has to look at the code.

      I could use the module like this:

      my $obscure = Business::CreditCard::Obscure->new(cardnum => '123456789 +012')->obscure();

      Since it is very specific, why don't you write your module to export a function, like this:

      use Business::CreditCard::Obscure qw(obscure); my $obscure = obscure(cardnum = '123456789012');

      Igor 'izut' Sutton
      your code, your rules.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2021-05-18 08:23 GMT
Find Nodes?
    Voting Booth?
    Perl 7 will be out ...

    Results (176 votes). Check out past polls.