| 1 | |||||||||||
| 2 | package Paper::Specs::base::brand; | ||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 1 | ▶ | use vars qw($VERSION); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | $VERSION=0.02; | |||||||||
| 7 | |||||||||||
| 8 | =head1 Paper::base::brand | ||||||||||
| 9 | |||||||||||
| 10 | Base class for brand information | ||||||||||
| 11 | |||||||||||
| 12 | =head1 | ||||||||||
| 13 | |||||||||||
| 14 | $things = Paper::Brand->find( '1234'); | ||||||||||
| 15 | |||||||||||
| 16 | Returns things that match the supplied code. Typical code name normalization is applied | ||||||||||
| 17 | |||||||||||
| 18 | =cut | ||||||||||
| 19 | |||||||||||
| 20 | 0 | ▶ | sub find { | ||||||||
|
Subroutine
find: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||
| 21 | |||||||||||
| 22 | 0 | my $self = shift; | |||||||||
| 23 | |||||||||||
| 24 | 0 | my $code = $self->normalize( shift ); | |||||||||
| 25 | 0 | ▶ | return "We need a code to search for\n" unless $code; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | |||||||||||
| 27 | 0 | eval "use ${self}::$code"; | |||||||||
| 28 | 0 | ▶ | return "${self}::$code"->new unless $@; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | |||||||||||
| 30 | 0 | ▶ | if ($Paper::Specs::debug) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | 0 | warn $@; | |||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | 0 | return (); | |||||||||
| 35 | |||||||||||
| 36 | } | ||||||||||
| 37 | |||||||||||
| 38 | =over | ||||||||||
| 39 | |||||||||||
| 40 | =item Class->normalize( code ) | ||||||||||
| 41 | |||||||||||
| 42 | Returnes a normalized code name for consistent searching. | ||||||||||
| 43 | |||||||||||
| 44 | - strip leading zeros from the code name | ||||||||||
| 45 | - strip leading spaces | ||||||||||
| 46 | - switch to all lower case | ||||||||||
| 47 | - switch spaces to "_" | ||||||||||
| 48 | |||||||||||
| 49 | =back | ||||||||||
| 50 | |||||||||||
| 51 | =cut | ||||||||||
| 52 | |||||||||||
| 53 | 0 | ▶ | sub normalize { | ||||||||
|
Subroutine
normalize: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 54 | |||||||||||
| 55 | 0 | my $code=$_[1]; | |||||||||
| 56 | |||||||||||
| 57 | 0 | $code =~ s/^0+//; | |||||||||
| 58 | 0 | $code =~ s/^\s+//; | |||||||||
| 59 | 0 | $code =~ s/\s+/_/; | |||||||||
| 60 | 0 | $code =~ tr/A-Z/a-z/; | |||||||||
| 61 | |||||||||||
| 62 | 0 | return $code; | |||||||||
| 63 | |||||||||||
| 64 | } | ||||||||||
| 65 | |||||||||||
| 66 | 1 | 1; | |||||||||
| 67 | |||||||||||