CLPM/Base.pm

filter: Statementstmt 33.3% 1 / 3 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 1 / 1 Podpod n/a totaltotal 50.0% 2 / 4 CC 1 SCAR 2.6
CC
1
Cov
33%
BEGIN
1.3
CRAP 1.3
↑ Summary CLPM/Fragments/Linked.pm »
1 package BioX::CLPM::Base;
2 0 ▶use Class::Std;
Subroutine BEGIN: called CC=1 SCAR=2.6
3 use Class::Std::Utils;
4 use DBIx::MySperqlOO;
5 use File::Spec;
6 use YAML qw(DumpFile LoadFile);
7  
8 use warnings;
9 use strict;
10 use Carp;
11  
12 use version; our $VERSION = qv('0.0.1');
13  
14 our $config_filename = '.clpm/config';
15  
16 {
17 #my %attribute_of :ATTR( :get<attribute> :set<attribute> :default<''> :init_arg<attribute> );
18 my %storage_of :ATTR( :get<storage> :set<storage> :default<'db'> :init_arg<storage> );
19 my %lookups_of :ATTR( :get<lookups> :set<lookups> :default<'local'> :init_arg<lookups> );
20 my %data_dbh_of : ATTR();
21  
22 sub BUILD {
23 my ($self, $ident, $arg_ref) = @_;
24 my $config = $self->_load_config();
25 $data_dbh_of{$ident} = DBIx::MySperqlOO->new( $config->{data} );
26 return;
27 }
28
29 sub get_config_filename { return File::Spec->catfile( $ENV{HOME}, $config_filename ); }
30  
31 sub sqlexec {
32 my ( $self, $sql, $return ) = @_;
33 my $data = $data_dbh_of{ident $self};
34 $sql = $sql ? $sql : '';
35 $return = $return ? $return : '';
36 if ( $return eq '\@@' ) {
37 my $rows_ref;
38 if ( $sql ) { $rows_ref = $data->sqlexec( $sql, $return ); }
39 return $rows_ref;
40 }
41 elsif ( $return eq '@' ) {
42 my @data;
43 if ( $sql ) { @data = $data->sqlexec( $sql, $return ); }
44 return @data;
45 }
46 }
47  
48 # UTIL
49 sub load_masses {
50 my ( $self ) = @_;
51 my $rows_ref = $self->sqlexec( 'select letter, mass from amino_acids', '\@@' );
52 my %aa_masses;
53 foreach my $row_ref ( @$rows_ref ) {
54 my ( $letter, $mass ) = @$row_ref;
55 $aa_masses{$letter} = $mass;
56 }
57 return \%aa_masses;
58 }
59  
60 sub _load_config {
61 my ( $self ) = @_;
62 return LoadFile( $self->get_config_filename() );
63 }
64
65 sub _sql_escape {
66 my ( $self, $string ) = @_;
67 if ($string) { $string =~ s/(['"\\])/\\$1/g; }
68 return $string;
69 }
70  
71 }
72  
73 1; # Magic true value required at end of module
74 __END__
↑ Summary CLPM/Fragments/Linked.pm »