-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enabled customized "separators" and updated documentation accordingly #13
base: master
Are you sure you want to change the base?
Conversation
Added a "separators" argument to the constructor to support customizable separators. Updated the documentation to demonstrate and explain how the "separators" argument is used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! Could you supply some additional tests for the newly exposed separators accessor as well? Also the current implementation is failing its tests...
@@ -33,13 +33,13 @@ has alphabet => ( | |||
|
|||
has chars => ( is => 'rwp', init_arg => undef, default => sub { [] } ); | |||
|
|||
has seps => ( | |||
has separators => ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can retain seps
here and just remove its init_arg
option so users can set it at object construction, e.g. Hashids->new( seps => 'aeiouy' )
:
has seps => (
is => 'rwp',
isa => sub {
local $_ = shift;
croak "$_ must not have spaces" if /\s/;
},
default => sub {
my @seps = qw(c f h i s t u);
join '' => @seps, map {uc} @seps;
},
);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with using "seps" rather than the longer "separators" keyword. I also like your suggestion for this preference because, now that I think of it, it can prevent problems resulting from a somewhat common misspelling that comes out as "seperators."
@@ -58,14 +58,15 @@ sub BUILD { | |||
if length $self->salt > length $self->alphabet; | |||
|
|||
my @alphabet = split // => $self->alphabet; | |||
my ( @seps, @guards ); | |||
my @seps = split // => $self->separators; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following the above, you won't need to split here...
for my $sep ( @{ $self->seps } ) { | ||
# separators should contain only chars present in alphabet; | ||
# alphabet should not contain separators | ||
for my $sep ( @seps ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... and instead do the split here.
Added a "separators" argument to the constructor to support customizable separators.
Updated the documentation to demonstrate and explain how the "separators" argument is used.