Permalink
Browse files

enhance constants_from performance!

  • Loading branch information...
1 parent ec1ff1d commit 78851f82b607ccfcaf224f11a016006ec60792fe @matiu committed Apr 18, 2011
Showing with 47 additions and 45 deletions.
  1. +6 −6 Makefile
  2. +8 −37 lib/SQL/Bibliosoph.pm
  3. +33 −2 lib/SQL/Bibliosoph/CatalogFile.pm
View
@@ -56,11 +56,11 @@ DIRFILESEP = /
DFSEP = $(DIRFILESEP)
NAME = SQL::Bibliosoph
NAME_SYM = SQL_Bibliosoph
-VERSION = 2.20
+VERSION = 2.21
VERSION_MACRO = VERSION
-VERSION_SYM = 2_20
+VERSION_SYM = 2_21
DEFINE_VERSION = -D$(VERSION_MACRO)=\"$(VERSION)\"
-XS_VERSION = 2.20
+XS_VERSION = 2.21
XS_VERSION_MACRO = XS_VERSION
XS_DEFINE_VERSION = -D$(XS_VERSION_MACRO)=\"$(XS_VERSION)\"
INST_ARCHLIB = blib/arch
@@ -269,7 +269,7 @@ RCS_LABEL = rcs -Nv$(VERSION_SYM): -q
DIST_CP = best
DIST_DEFAULT = tardist
DISTNAME = SQL-Bibliosoph
-DISTVNAME = SQL-Bibliosoph-2.20
+DISTVNAME = SQL-Bibliosoph-2.21
# --- MakeMaker macro section:
@@ -496,7 +496,7 @@ metafile : create_distdir
$(NOECHO) $(ECHO) Generating META.yml
$(NOECHO) $(ECHO) '--- #YAML:1.0' > META_new.yml
$(NOECHO) $(ECHO) 'name: SQL-Bibliosoph' >> META_new.yml
- $(NOECHO) $(ECHO) 'version: 2.20' >> META_new.yml
+ $(NOECHO) $(ECHO) 'version: 2.21' >> META_new.yml
$(NOECHO) $(ECHO) 'abstract: A SQL Query library' >> META_new.yml
$(NOECHO) $(ECHO) 'author:' >> META_new.yml
$(NOECHO) $(ECHO) ' - Matias Alejo Garcia ( matiu@cpan.org ) ' >> META_new.yml
@@ -820,7 +820,7 @@ testdb_static :: testdb_dynamic
# --- MakeMaker ppd section:
# Creates a PPD (Perl Package Description) for a binary distribution.
ppd :
- $(NOECHO) $(ECHO) '<SOFTPKG NAME="$(DISTNAME)" VERSION="2.20">' > $(DISTNAME).ppd
+ $(NOECHO) $(ECHO) '<SOFTPKG NAME="$(DISTNAME)" VERSION="2.21">' > $(DISTNAME).ppd
$(NOECHO) $(ECHO) ' <ABSTRACT>A SQL Query library</ABSTRACT>' >> $(DISTNAME).ppd
$(NOECHO) $(ECHO) ' <AUTHOR>Matias Alejo Garcia ( matiu@cpan.org ) </AUTHOR>' >> $(DISTNAME).ppd
$(NOECHO) $(ECHO) ' <IMPLEMENTATION>' >> $(DISTNAME).ppd
View
@@ -10,7 +10,7 @@ package SQL::Bibliosoph; {
use SQL::Bibliosoph::Query;
use SQL::Bibliosoph::CatalogFile;
- our $VERSION = "2.21";
+ our $VERSION = "2.22";
has 'dbh' => ( is => 'ro', isa => 'DBI::db', required=> 1);
@@ -54,7 +54,8 @@ package SQL::Bibliosoph; {
foreach my $fname (@{ $self->catalog() }) {
$self->do_all_for(
SQL::Bibliosoph::CatalogFile->new(
- file => $self->path() . $fname,
+ file => $self->path() . $fname,
+ constants_from => $self->constants_from(),
)->read()
);
}
@@ -105,7 +106,6 @@ package SQL::Bibliosoph; {
sub do_all_for {
my ($self,$qs) = @_;
- $self->replace_contants($qs);
$self->create_queries_from($qs);
$self->create_methods_from($qs);
}
@@ -427,39 +427,6 @@ package SQL::Bibliosoph; {
}
#------------------------------------------------------------------
- sub replace_contants {
- my ($self,$qs) =@_;
-
- my $p = $self->constants_from() or return;
-
- eval {
-
- # Read constants
- eval "require $p";
-
- import $p;
- my @cs = Package::Constants->list($p);
-
- $self->d("\tConstants from $p [".@cs."]\n");
-
-
- # DO Replace constants
- foreach my $v (values %$qs) {
- next if !$v;
-
- foreach my $key (@cs) {
- my $value = eval "$key" ;
- $v =~ s/\b$key\b/$value/g;
- }
- }
- };
- if ($@) {
- die "error importing constants from $p : $@";
- }
- }
-
-
- #------------------------------------------------------------------
sub create_queries_from {
my ($self,$qs) = @_;
my $i = 0;
@@ -481,7 +448,8 @@ package SQL::Bibliosoph; {
benchmark=> $self->benchmark(),
throw_errors => $self->throw_errors(),
};
- #print STDERR " Query for ".Dumper($args);
+
+ # print STDERR " Query for ".Dumper($args);
# Prepare the statement
$self->queries()->{$name} = SQL::Bibliosoph::Query->new( $args );
@@ -666,6 +634,7 @@ statement will be prepared at module constuction.
Allows to define a SQL catalog using a string (not a file). The queries will be
merged with Catalog files (if any).
+
=head3 constants_from
@@ -674,6 +643,8 @@ can declare a module using `constants_from` paramenter. Constants exported in
that module (using @EXPORT) will be replaced in all catalog file before SQL
preparation. The module must be in the @INC path.
+Note: constants_from() is ignored in 'catalog_str' queries (sorry, not implemented, yet)
+
=head3 delayed
Do not prepare all the statements at startup. They will be prepared individualy,
@@ -3,11 +3,13 @@ package SQL::Bibliosoph::CatalogFile; {
use utf8;
use Carp;
use Data::Dumper;
+ use Package::Constants;
our $VERSION = "2.00";
- has file => ( is => 'rw', isa=>'Str', required => 1 );
- has read_only=> ( is => 'rw', isa=>'Bool', default => 0 );
+ has file => ( is => 'rw', isa=>'Str', required => 1 );
+ has read_only => ( is => 'rw', isa=>'Bool', default => 0 );
+ has 'constants_from' => ( is => 'ro', isa => 'Maybe[Str]');
#------------------------------------------------------------------
@@ -26,11 +28,40 @@ package SQL::Bibliosoph::CatalogFile; {
croak "File does not exists $file " if ! -e $file;
}
+ #------------------------------------------------------------------
+ sub replace_contants {
+ my ($self, $pstr) =@_;
+
+ my $p = $self->constants_from() or return;
+
+ eval {
+
+ # Read constants
+ eval "require $p";
+
+ import $p;
+ my @cs = Package::Constants->list($p);
+
+ # DO Replace constants
+ foreach my $key (@cs) {
+ my $value = eval "$key" ;
+ $$pstr =~ s/\b$key\b/$value/g;
+ }
+ };
+ if ($@) {
+ die "error importing constants from $p : $@";
+ }
+ }
+
+ #------------------------------------------------------------------
+
sub read {
my ($self) = @_;
my $file_contents= $self->file_to_str( $self->file() );
+ $self->replace_contants(\$file_contents);
+
my $qs = $self->_parse($file_contents);
# Read only?

0 comments on commit 78851f8

Please sign in to comment.