Permalink
Browse files

Merge branch 'master' of github.com:sugar84/addressbook

  • Loading branch information...
antonuk84@yandex.ru
antonuk84@yandex.ru committed Apr 21, 2011
2 parents 9e35df4 + 5153176 commit 049d2ed5b689ea97bbadc34e13bdec8dd8e1423d
Showing with 11 additions and 124 deletions.
  1. +0 −30 lib/AddressBook.pm
  2. +0 −27 lib/AddressBook/DB2.pm~
  3. +11 −22 lib/AddressBook/Plugin/MountCode.pm
  4. +0 −45 lib/AddressBook/Plugin/MountCode.pm~
View
@@ -18,44 +18,15 @@ my $sql_blocks = do $sqls_file;
# dirty utf8 hack for Dumper
$Data::Dumper::Useqq = 1;
-
{ no warnings 'redefine';
sub Data::Dumper::qqoute {
my $s = shift;
return "'$s'";
}
}
-### Subs
-#
-
-#sub test_select {
-# my $sth = database->prepare( $sql_blocks->{"test_select"} )
-# or croak database->errstr;
-# $sth->execute
-# or croak $sth->errstr;
-# my $entries = $sth->fetchall_hashref("org_id")
-# or croak $sth->errstr;
-#
-# return $entries;
-#}
-
warning caller;
mount_code;
-#
-#open my $fh, "<", "lib/AddressBook/DB2.pm"
-# or croak "cannot open the file $!";
-#my $code = do { local $/ = undef; <$fh> };
-#close $fh;
-#eval $code;
-#warning $code;
-#warning $@ if $@;
-#warning show_settings();
-#eval
-#use AddressBook::DB2;
-#use DB;
-#load "DB.pm";
-#DB->import( qw(test_select) );
### Handlers
@@ -74,5 +45,4 @@ get '/' => sub {
template 'home';
};
-#init_db();
true;
View
@@ -1,27 +0,0 @@
-#package AddressBook::DB2;
-#use strict;
-#use Dancer qw(:syntax);
-#use Dancer::Plugin::Database;
-#use Carp;
-#use base "Exporter";
-#our @EXPORT = qw(test_select);
-
-## Config
-my $sql_file = "SQL/sql.pl"; # here lye sql statements;
-my $sql_ref = do $sql_file;
-print STDERR caller();
-warning caller;
-
-sub test_select {
- my $sth = database->prepare( $sql_ref->{"test_select"} )
- or croak database->errstr;
- $sth->execute
- or croak $sth->errstr;
- my $entries = $sth->fetchall_hashref("org_id")
- or croak $sth->errstr;
-
- return $entries;
-}
-
-warning "hello!\n";
-true;
@@ -5,40 +5,29 @@ use warnings;
use Dancer qw(:syntax);
use Dancer::Plugin;
use Carp;
-use Data::Dumper;
+#use Data::Dumper;
my $settings = plugin_setting;
-register show_settings => sub {
- print Dumper($settings);
-};
-
register mount_code => sub {
- while (my ($description, $file) = each %{$settings}) {
+ while ( my ($description, $file) = each %{$settings} ) {
open my $fh, "<", $file
or croak "cannot open $file at $description : $!\n";
-
- my $code = do { local $/= undef; <$fh> };
-# warning caller;
- my $current_pack = __PACKAGE__;
- my $caller_pack = caller;
- warning $caller_pack;
-# {
-# no strict 'refs';
-# *{$caller_pack . "::"} = \*{$current_pack . "::"};
-# }
- my $eval = qq/package $caller_pack;\n $code/;
-# warning __PACKAGE__;
+
+ my $code = do { local $/ = undef; <$fh> };
+
+ my $caller_package = caller;
+ my $eval = qq/package $caller_package;\n $code/;
eval $eval;
+
if ($@) {
- croak "while execution code some errors occured see the:\n" .
- "$description" . ":" . "$file";
+ croak "while execution code some errors occured. $@\n" .
+ "See file from the line of your app's config:\n" .
+ "\t" . "$description" . ": " . "$file" . "\n";
}
}
-# test_select();
};
-
register_plugin;
1;
@@ -1,45 +0,0 @@
-package AddressBook::Plugin::MountCode;
-use strict;
-use warnings;
-
-use Dancer qw(:syntax);
-use Dancer::Plugin;
-use Carp;
-use Data::Dumper;
-
-my $settings = plugin_setting;
-
-register show_settings => sub {
- print Dumper($settings);
-};
-
-register mount_code => sub {
- while (my ($description, $file) = each %{$settings}) {
- open my $fh, "<", $file
- or croak "cannot open $file at $description : $!\n";
-
- my $code = do { local $/= undef; <$fh> };
- warning caller;
- my $current_pack = __PACKAGE__;
- my $caller_pack = caller;
- warning $current_pack;
-# {
-# no strict 'refs';
-# *{$caller_pack . "::"} = \*{$current_pack . "::"};
-# }
- my $eval = qq/package $caller_pack;\n $code/;
- warning __PACKAGE__;
- eval $eval;
- if ($@) {
- croak "while execution code some errors occured see the:\n" .
- "$description" . ":" . "$file";
- }
- }
-# test_select();
-};
-
-
-register_plugin;
-
-1;
-

0 comments on commit 049d2ed

Please sign in to comment.