| 1 | package Hints::Base; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use Hints; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use IO::Handle; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use vars qw/$VERSION @ISA/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 1 | $VERSION = '0.02'; | |||||||||
| 9 | 1 | @ISA = qw/Hints/; | |||||||||
| 10 | |||||||||||
| 11 | =head1 NAME | ||||||||||
| 12 | |||||||||||
| 13 | Hints::Base - Perl extension for hints program storage databases | ||||||||||
| 14 | |||||||||||
| 15 | =head1 SYNOPSIS | ||||||||||
| 16 | |||||||||||
| 17 | use Hints::Base; | ||||||||||
| 18 | |||||||||||
| 19 | my $hints = new Hints::Base 'program'; | ||||||||||
| 20 | |||||||||||
| 21 | print $hints->random(); | ||||||||||
| 22 | |||||||||||
| 23 | =head1 DESCRIPTION | ||||||||||
| 24 | |||||||||||
| 25 | Specialized version of Hints(3) extension. This variant can be used for | ||||||||||
| 26 | internal program storage database of hints. Descendant contents databases, | ||||||||||
| 27 | this module implement loading of databases from internal data storage. | ||||||||||
| 28 | |||||||||||
| 29 | =head1 THE HINTS::BASE CLASS | ||||||||||
| 30 | |||||||||||
| 31 | =head2 init | ||||||||||
| 32 | |||||||||||
| 33 | Loading data storage between __DATA__ and __END__ or EOF tags. Using | ||||||||||
| 34 | default separator. | ||||||||||
| 35 | |||||||||||
| 36 | =cut | ||||||||||
| 37 | |||||||||||
| 38 | 3 | ▶ | sub init { | ||||||||
|
Subroutine
init: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||
| 39 | 3 | my $obj = shift; | |||||||||
| 40 | 3 | my $next = shift; | |||||||||
| 41 | 3 | ▶ | if ($next) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 42 | 1 | my $nextname = "Hints::Base::$next"; | |||||||||
| 43 | 1 | eval "package Hints::Base::_safe; require $nextname;"; | |||||||||
| 44 | 1 | ▶ | unless ($@) { # database | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | 1 | $nextname->import(); | |||||||||
| 46 | 1 | return $nextname->new(@_); | |||||||||
| 47 | } | ||||||||||
| 48 | } | ||||||||||
| 49 | 2 | my @data = (); | |||||||||
| 50 | 2 | my $sourcepkg = ref $obj; | |||||||||
| 51 | 1 | ▶ | no strict 'refs'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 52 | 2 | my $fh = \*{"${sourcepkg}::DATA"}; | |||||||||
| 53 | 1 | ▶ | use strict 'refs'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 54 | 2 | ▶ | while (<$fh>) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | 40 | ▶ | last if /^__END__$/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | 38 | push @data,$_; | |||||||||
| 57 | } | ||||||||||
| 58 | 2 | $obj->load_from_file(\@data); | |||||||||
| 59 | 2 | $obj; | |||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | 1 | 1; | |||||||||
| 63 | |||||||||||
| 64 | __DATA__ | ||||||||||