| 1 | package Text::Cipher; | ||||||||||
| 2 | |||||||||||
| 3 | # This package is the base package for all Crypt::Ciphers, providing | ||||||||||
| 4 | # an encapsulated and easily inheritable framework for building | ||||||||||
| 5 | # ciphers. See the POD for more details on the user side. | ||||||||||
| 6 | |||||||||||
| 7 | # The implementation of this program is currently based on the | ||||||||||
| 8 | # Regexp::Tr class and inherits from there. | ||||||||||
| 9 | |||||||||||
| 10 | |||||||||||
| 11 | # Boilerplate package beginning | ||||||||||
| 12 | 1 | ▶ | use 5.006; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 1 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | |||||||||||
| 17 | # Implementation-specific imports and constants | ||||||||||
| 18 | 1 | ▶ | use Regexp::Tr v0.05; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | 1 | ▶ | use constant { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | 1 | UPPERCASE => join("","A".."Z"), | |||||||||
| 21 | LOWERCASE => join("","a".."z"), | ||||||||||
| 22 | NUMBERS => join("",0..9) | ||||||||||
| 23 | 1 | }; | |||||||||
| 24 | |||||||||||
| 25 | # UNIVERSAL class variables | ||||||||||
| 26 | 1 | our @ISA = qw(Regexp::Tr); | |||||||||
| 27 | 1 | our $VERSION = "1.01"; | |||||||||
| 28 | |||||||||||
| 29 | 1 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 30 | 1 | *clean = \&Regexp::Tr::flush; | |||||||||
| 31 | 1 | *encipher_scalar = \&Regexp::Tr::bind; | |||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | 1 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||
| 35 | 1 | my($from, $to, $mods) = @_; | |||||||||
| 36 | 1 | ▶ | $mods .= "d" unless($mods =~ /d/); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | 1 | return Regexp::Tr::new($from, $to, $mods); | |||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | 4 | ▶ | sub encipher { | ||||||||
|
Subroutine
encipher: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 41 | 4 | my($self,$val) = (shift,shift); | |||||||||
| 42 | 4 | Regexp::Tr::bind($self, \$val); | |||||||||
| 43 | 4 | return $val; | |||||||||
| 44 | } | ||||||||||
| 45 | |||||||||||
| 46 | 0 | ▶ | sub encipher_string { | ||||||||
|
Subroutine
encipher_string: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 47 | 0 | my $obj = shift; | |||||||||
| 48 | 0 | return $obj->encipher(@_); | |||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | 1 | ▶ | sub encipher_list { | ||||||||
|
Subroutine
encipher_list: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 52 | 1 | my $self = shift; | |||||||||
| 53 | 1 | return map { scalar($self->encipher($_)) } @_; | |||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | 1 | ▶ | sub encipher_array { | ||||||||
|
Subroutine
encipher_array: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||
| 57 | 1 | my($self,$ref) = @_; | |||||||||
| 58 | 1 | ▶ | carp "Parameter passed is not an array ref" unless(ref($ref) eq "ARRAY"); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 59 | 1 | my @refarray = \(@{$ref}); | |||||||||
| 60 | 1 | eval { map { scalar($self->encipher_scalar($_)) } @refarray }; | |||||||||
| 61 | 1 | ▶ | die "Error in encipher_array: $@" if($@); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | |||||||||||
| 65 | 1 | return 1; | |||||||||
| 66 | __END__ | ||||||||||