| 1 | package SQL::Library; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 1 | our $VERSION = '0.0.5'; | |||||||||
| 7 | |||||||||||
| 8 | sub new | ||||||||||
| 9 | 1 | ▶ | { | ||||||||
|
Subroutine
new: called CC=10 SCAR=25.3
Pod
documented
| |||||||||||
| 10 | 1 | my $proto = shift; | |||||||||
| 11 | 1 | my $options = shift; | |||||||||
| 12 | 1 | my $self = { | |||||||||
| 13 | 'options' => $options, | ||||||||||
| 14 | 'contents' => undef | ||||||||||
| 15 | }; | ||||||||||
| 16 | |||||||||||
| 17 | 1 | my $curr_name = ''; | |||||||||
| 18 | |||||||||||
| 19 | 1 | my @lib_arr = (); | |||||||||
| 20 | 1 | ▶ | if ( ref $self->{'options'}->{'lib'} eq 'ARRAY' ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 21 | { | ||||||||||
| 22 | # Could be a filehandle or a string. | ||||||||||
| 23 | 0 | ▶ | if ( @{ $self->{'options'}->{'lib'} } == 1 ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | { | ||||||||||
| 25 | 0 | @lib_arr = split /(?<=\n)/, $self->{'options'}->{'lib'}->[0]; | |||||||||
| 26 | } | ||||||||||
| 27 | else | ||||||||||
| 28 | { | ||||||||||
| 29 | 0 | @lib_arr = @{ $self->{'options'}->{'lib'} }; | |||||||||
| 30 | } | ||||||||||
| 31 | } | ||||||||||
| 32 | else | ||||||||||
| 33 | { | ||||||||||
| 34 | 1 | ▶ | open LIB, $self->{'options'}->{'lib'} | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | or die "Cannot open $self->{'options'}->{'lib'}: $!"; | ||||||||||
| 36 | 1 | @lib_arr = <LIB>; | |||||||||
| 37 | 1 | close LIB; | |||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | 1 | foreach ( @lib_arr ) | |||||||||
| 41 | { | ||||||||||
| 42 | 10 | ▶ | next if m{^\s*$}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | 8 | ▶ | next if m{^\s*#}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | 8 | ▶ | next if m{^\s*//}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | 8 | ▶ | if ( m{^\[([^\]]+)\]} ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | { | ||||||||||
| 47 | 2 | $curr_name = $1; | |||||||||
| 48 | 2 | next; | |||||||||
| 49 | } | ||||||||||
| 50 | 6 | ▶ | if ( $curr_name ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | { | ||||||||||
| 52 | 6 | $self->{'contents'}->{$curr_name} .= $_; | |||||||||
| 53 | } | ||||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | 1 | bless $self, $proto; | |||||||||
| 57 | 1 | return $self; | |||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | sub retr | ||||||||||
| 61 | 4 | ▶ | { | ||||||||
|
Subroutine
retr: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 62 | 4 | my ( $self, $entity_name ) = @_; | |||||||||
| 63 | 4 | return $self->{'contents'}->{$entity_name}; | |||||||||
| 64 | } | ||||||||||
| 65 | |||||||||||
| 66 | sub set | ||||||||||
| 67 | 2 | ▶ | { | ||||||||
|
Subroutine
set: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 68 | 2 | my ( $self, $entity_name, $entity ) = @_; | |||||||||
| 69 | 2 | $self->{'contents'}->{$entity_name} = $entity; | |||||||||
| 70 | 2 | return $self; | |||||||||
| 71 | } | ||||||||||
| 72 | |||||||||||
| 73 | sub drop | ||||||||||
| 74 | 1 | ▶ | { | ||||||||
|
Subroutine
drop: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 75 | 1 | my ( $self, $entity_name ) = @_; | |||||||||
| 76 | 1 | delete $self->{'contents'}->{$entity_name}; | |||||||||
| 77 | 1 | return $self; | |||||||||
| 78 | } | ||||||||||
| 79 | |||||||||||
| 80 | sub elements | ||||||||||
| 81 | 1 | ▶ | { | ||||||||
|
Subroutine
elements: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 82 | 1 | my $self = shift; | |||||||||
| 83 | 1 | return sort keys %{$self->{'contents'}}; | |||||||||
| 84 | } | ||||||||||
| 85 | |||||||||||
| 86 | sub dump | ||||||||||
| 87 | 1 | ▶ | { | ||||||||
|
Subroutine
dump: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 88 | 1 | my $self = shift; | |||||||||
| 89 | 1 | my $output = ''; | |||||||||
| 90 | 1 | foreach ( sort keys %{$self->{'contents'}} ) | |||||||||
| 91 | { | ||||||||||
| 92 | 2 | $output .= sprintf "[%s]\n%s\n", $_, $self->{'contents'}->{$_}; | |||||||||
| 93 | } | ||||||||||
| 94 | 1 | return $output; | |||||||||
| 95 | } | ||||||||||
| 96 | |||||||||||
| 97 | sub write | ||||||||||
| 98 | 0 | ▶ | { | ||||||||
|
Subroutine
write: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 99 | 0 | my $self = shift; | |||||||||
| 100 | 0 | ▶ | open OUT, ">$self->{'options'}->{'lib'}" | ||||||||
|
Branch: 1 branch
| |||||||||||
| 101 | or die "Cannot open $self->{'options'}->{'lib'}: $!"; | ||||||||||
| 102 | 0 | print OUT $self->dump; | |||||||||
| 103 | 0 | close OUT; | |||||||||
| 104 | } | ||||||||||
| 105 | |||||||||||
| 106 | 1 | 1 ; | |||||||||
| 107 | __END__ | ||||||||||