Hi, I’m getting a bit confused with plugins. I’m sure that I was able to use the DBIC Plugin at one point from one of my plugins, but I can’t seem to get it to work in 0.159002 or 0.160000. DBIC seems to be okay outside of plugins. 3 questions: * why does it complain about "Plugin calls 'dsl' instead of '$dsl->dsl’" when I appear to be using '$dsl->dsl’? * how do I get DBIC to print the SQL it’s executing so I can double check it’s what I’m expecting? * am I doing something else wrong in the way I’m trying to use DBIC? Basically this is the code in my plugin: register get_topics => sub { my $dsl = shift; my $type = shift; my $application = shift; my $pageid = shift; my $dberr = 0; my $current; my $urlref; my $template = ""; my $id; my @topics; $dsl->debug( "**** Here 1 ****"); eval { @topics = $dsl->schema->resultset('ContentType')->search({ application => $application }, { prefetch => [ 'content_type_names' ], order_by => 'sort_order' }) }; $dberr += $dsl->check_db_result( $dsl, $@, __LINE__ ); $dsl->debug( "**** Here 2 **** " . @topics); etc, etc } The output in the console is this: [Routes:37674] core @2015-04-27 21:57:16> Entering hook core.app.before_request in (eval 87) l. 1 [Routes:37674] debug @2015-04-27 21:57:16> **** Here 1 **** in /code/Dancer/MediBase/bin/../lib/QTechLib/Plugin.pm l. 31 DEPRECATED: QTechLib::Plugin calls 'dsl' instead of '$dsl->dsl'. at /perf/perl/lib/perl5/Dancer2/Plugin/DBIC.pm line 13. [Routes:37674] debug @2015-04-27 21:57:16> ######Dancer2::Core::DSL__WITH__Dancer2::Plugin::DBIC__WITH__Dancer2::Plugin::Ajax__WITH__QTechLib::L12N::Plugin__WITH__QTechLib::Plugin=HASH(0x3a05a88)###### at line: in /code/Dancer/MediBase/bin/../lib/QTechLib/Plugin.pm l. 66 [Routes:37674] debug @2015-04-27 21:57:16> **** Here 2 **** in /code/Dancer/MediBase/bin/../lib/QTechLib/Plugin.pm l. 31 Here 2 should print the number of topics - which should be greater than zero. with thanks, Matt
On Mon, 2015-04-27 at 22:26 +1000, Matthew Mallard wrote:
I’m getting a bit confused with plugins. I’m sure that I was able to use the DBIC Plugin at one point from one of my plugins, but I can’t seem to get it to work in 0.159002 or 0.160000. DBIC seems to be okay outside of plugins.
Firstly, there is change going on in the world of plugins, which I suspect will fix this, but I haven't read up on the full details myself: http://lists.preshweb.co.uk/pipermail/dancer-users/2015-April/004512.html
3 questions: * why does it complain about "Plugin calls 'dsl' instead of '$dsl->dsl’" when I appear to be using '$dsl->dsl’?
Are you using an old version of the DBIC plugin? I think that is fixed in the most recent version.
* how do I get DBIC to print the SQL it’s executing so I can double check it’s what I’m expecting? * am I doing something else wrong in the way I’m trying to use DBIC?
This is a bit more tricky. With the current plugin architecture, "schema" is not available in the DSL when you call it from another plugin as you are doing. You can workaround this by capturing it during plugin initialisation, as long as you load the DBIC plugin before yours. See Plugin::Auth::Extensible::Provider::DBIC for an example: https://github.com/ctrlo/Dancer2-Plugin-Auth-Extensible-Provider-DBIC/blob/m... Andy
Andrew, thanks for your suggestions. It’s pushing me beyond the plugins usage the documentation covers, would you be able to elaborate on how to achieve what you are suggesting (I don’t quite get all the flows within the auth/extensible plugin). So do I create a sub in my custom plugin along these lines: sub new { my ($class, $dsl) = @_; # Grab a handle to the Plugin::DBIC schema die "No schema method in app. Did you load DBIC::Plugin::DBIC before My::Custom::Module?" unless $dsl->can('schema'); my $schema = $dsl->schema; my $self = { dsl_local => $dsl, schema => $schema, }; return bless $self => $class; } Then in my routes module I call plugins in this order: use Dancer2::Plugin::DBIC use My::Custom::Module How does 'new' get called and what do I use to reference the schema in my custom plugin. Let me know if there is some other background reading I should be doing for how this work, Thanks, Matt PS - I am using version 0.0009 of Dancer2::Plugin::DBIC which I believe is the latest. On 28 Apr 2015, at 5:51 pm, Andrew Beverley <andy@andybev.com> wrote:
On Mon, 2015-04-27 at 22:26 +1000, Matthew Mallard wrote:
I’m getting a bit confused with plugins. I’m sure that I was able to use the DBIC Plugin at one point from one of my plugins, but I can’t seem to get it to work in 0.159002 or 0.160000. DBIC seems to be okay outside of plugins.
Firstly, there is change going on in the world of plugins, which I suspect will fix this, but I haven't read up on the full details myself:
http://lists.preshweb.co.uk/pipermail/dancer-users/2015-April/004512.html
3 questions: * why does it complain about "Plugin calls 'dsl' instead of '$dsl->dsl’" when I appear to be using '$dsl->dsl’?
Are you using an old version of the DBIC plugin? I think that is fixed in the most recent version.
* how do I get DBIC to print the SQL it’s executing so I can double check it’s what I’m expecting? * am I doing something else wrong in the way I’m trying to use DBIC?
This is a bit more tricky. With the current plugin architecture, "schema" is not available in the DSL when you call it from another plugin as you are doing. You can workaround this by capturing it during plugin initialisation, as long as you load the DBIC plugin before yours. See Plugin::Auth::Extensible::Provider::DBIC for an example:
https://github.com/ctrlo/Dancer2-Plugin-Auth-Extensible-Provider-DBIC/blob/m...
Andy
_______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
On Sat, 2015-05-02 at 12:50 +1000, Matthew Mallard wrote:
I’m getting a bit confused with plugins. I’m sure that I was able to use the DBIC Plugin at one point from one of my plugins, but I can’t seem to get it to work in 0.159002 or 0.160000. DBIC seems to be okay outside of plugins.
Firstly, there is change going on in the world of plugins, which I suspect will fix this, but I haven't read up on the full details myself:
http://lists.preshweb.co.uk/pipermail/dancer-users/2015-April/004512.html
* how do I get DBIC to print the SQL it’s executing so I can double check it’s what I’m expecting? * am I doing something else wrong in the way I’m trying to use DBIC?
This is a bit more tricky. With the current plugin architecture, "schema" is not available in the DSL when you call it from another plugin as you are doing. You can workaround this by capturing it during plugin initialisation, as long as you load the DBIC plugin before yours. See Plugin::Auth::Extensible::Provider::DBIC for an example:
So do I create a sub in my custom plugin along these lines: sub new { my ($class, $dsl) = @_;
# Grab a handle to the Plugin::DBIC schema die "No schema method in app. Did you load DBIC::Plugin::DBIC before My::Custom::Module?" unless $dsl->can('schema'); my $schema = $dsl->schema;
Yes, similar to that, but using on_plugin_import. See this example: https://github.com/PerlDancer/Dancer2-Plugin-Auth-Extensible/blob/de84a4a5ba...
my $self = { dsl_local => $dsl, schema => $schema, }; return bless $self => $class;
I don't think you need to bless your class, as it's already blessed. You just need to store the schema in a global in your module, a bit like $settings here: https://github.com/PerlDancer/Dancer2-Plugin-Auth-Extensible/blob/de84a4a5ba...
Then in my routes module I call plugins in this order: use Dancer2::Plugin::DBIC use My::Custom::Module
Yes.
How does 'new' get called and what do I use to reference the schema in my custom plugin.
See above.
Let me know if there is some other background reading I should be doing for how this work,
To be honest, it's a dirty hack, so you won't find any documentation on it. You might be better waiting for the new plugin architecture if you can. Andy
Andy, Thanks again for your help. This code works: my $schema; on_plugin_import { my $dsl = shift; # Grab a handle to the Plugin::DBIC schema die "No schema method in app. Did you load DBIC::Plugin::DBIC before Custom::Plugin?" unless $dsl->can('schema'); $schema = $dsl->schema; $dsl->debug( "**** Got Schema **** "); }; Having said that, I realise the original code would have worked too but too many things were changing at the same time and it caught me out. I moved from mysql to postgresql and the case sensitivity was causing a problem, there were rather radical changes in the way Dancer2 was requiring me to structure my code and to top it off the "DEPRECATED: Custom::Plugin calls 'dsl' instead of '$dsl->dsl'. at /perf/perl/lib/perl5/Dancer2/Plugin/DBIC.pm line 13.” was making me think I was on the wrong track. But this warning remains even with the new code. Turning statement logging on in postgres helped me track down the case mismatch. Cheers, Matt On 2 May 2015, at 7:47 pm, Andrew Beverley <andy@andybev.com> wrote:
On Sat, 2015-05-02 at 12:50 +1000, Matthew Mallard wrote:
I’m getting a bit confused with plugins. I’m sure that I was able to use the DBIC Plugin at one point from one of my plugins, but I can’t seem to get it to work in 0.159002 or 0.160000. DBIC seems to be okay outside of plugins.
Firstly, there is change going on in the world of plugins, which I suspect will fix this, but I haven't read up on the full details myself:
http://lists.preshweb.co.uk/pipermail/dancer-users/2015-April/004512.html
* how do I get DBIC to print the SQL it’s executing so I can double check it’s what I’m expecting? * am I doing something else wrong in the way I’m trying to use DBIC?
This is a bit more tricky. With the current plugin architecture, "schema" is not available in the DSL when you call it from another plugin as you are doing. You can workaround this by capturing it during plugin initialisation, as long as you load the DBIC plugin before yours. See Plugin::Auth::Extensible::Provider::DBIC for an example:
So do I create a sub in my custom plugin along these lines: sub new { my ($class, $dsl) = @_;
# Grab a handle to the Plugin::DBIC schema die "No schema method in app. Did you load DBIC::Plugin::DBIC before My::Custom::Module?" unless $dsl->can('schema'); my $schema = $dsl->schema;
Yes, similar to that, but using on_plugin_import. See this example:
https://github.com/PerlDancer/Dancer2-Plugin-Auth-Extensible/blob/de84a4a5ba...
my $self = { dsl_local => $dsl, schema => $schema, }; return bless $self => $class;
I don't think you need to bless your class, as it's already blessed. You just need to store the schema in a global in your module, a bit like $settings here:
https://github.com/PerlDancer/Dancer2-Plugin-Auth-Extensible/blob/de84a4a5ba...
Then in my routes module I call plugins in this order: use Dancer2::Plugin::DBIC use My::Custom::Module
Yes.
How does 'new' get called and what do I use to reference the schema in my custom plugin.
See above.
Let me know if there is some other background reading I should be doing for how this work,
To be honest, it's a dirty hack, so you won't find any documentation on it. You might be better waiting for the new plugin architecture if you can.
Andy
_______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
What version of the DBIC plugin are you using? If you are not using the latest, can you upgrade and let me know if you still get the same warning. Thanks, Naveed (DBIC plugin author) On Sat, May 2, 2015 at 7:34 AM, Matthew Mallard <matt@q-technologies.com.au> wrote:
Andy,
Thanks again for your help. This code works: my $schema;
on_plugin_import { my $dsl = shift; # Grab a handle to the Plugin::DBIC schema die "No schema method in app. Did you load DBIC::Plugin::DBIC before Custom::Plugin?" unless $dsl->can('schema'); $schema = $dsl->schema; $dsl->debug( "**** Got Schema **** "); };
Having said that, I realise the original code would have worked too but too many things were changing at the same time and it caught me out. I moved from mysql to postgresql and the case sensitivity was causing a problem, there were rather radical changes in the way Dancer2 was requiring me to structure my code and to top it off the "DEPRECATED: Custom::Plugin calls 'dsl' instead of '$dsl->dsl'. at /perf/perl/lib/perl5/Dancer2/Plugin/DBIC.pm line 13.” was making me think I was on the wrong track. But this warning remains even with the new code.
Turning statement logging on in postgres helped me track down the case mismatch.
Cheers, Matt
On 2 May 2015, at 7:47 pm, Andrew Beverley <andy@andybev.com> wrote:
On Sat, 2015-05-02 at 12:50 +1000, Matthew Mallard wrote:
I’m getting a bit confused with plugins. I’m sure that I was able to use the DBIC Plugin at one point from one of my plugins, but I can’t seem to get it to work in 0.159002 or 0.160000. DBIC seems to be okay outside of plugins.
Firstly, there is change going on in the world of plugins, which I suspect will fix this, but I haven't read up on the full details myself:
http://lists.preshweb.co.uk/pipermail/dancer-users/2015-April/004512.html
* how do I get DBIC to print the SQL it’s executing so I can double check it’s what I’m expecting? * am I doing something else wrong in the way I’m trying to use DBIC?
This is a bit more tricky. With the current plugin architecture, "schema" is not available in the DSL when you call it from another plugin as you are doing. You can workaround this by capturing it during plugin initialisation, as long as you load the DBIC plugin before
yours.
See Plugin::Auth::Extensible::Provider::DBIC for an example:
So do I create a sub in my custom plugin along these lines: sub new { my ($class, $dsl) = @_;
# Grab a handle to the Plugin::DBIC schema die "No schema method in app. Did you load DBIC::Plugin::DBIC before My::Custom::Module?" unless $dsl->can('schema'); my $schema = $dsl->schema;
Yes, similar to that, but using on_plugin_import. See this example:
https://github.com/PerlDancer/Dancer2-Plugin-Auth-Extensible/blob/de84a4a5ba...
my $self = { dsl_local => $dsl, schema => $schema, }; return bless $self => $class;
I don't think you need to bless your class, as it's already blessed. You just need to store the schema in a global in your module, a bit like $settings here:
https://github.com/PerlDancer/Dancer2-Plugin-Auth-Extensible/blob/de84a4a5ba...
Then in my routes module I call plugins in this order: use Dancer2::Plugin::DBIC use My::Custom::Module
Yes.
How does 'new' get called and what do I use to reference the schema in
my custom plugin.
See above.
Let me know if there is some other background reading I should be doing for how this work,
To be honest, it's a dirty hack, so you won't find any documentation on it. You might be better waiting for the new plugin architecture if you can.
Andy
_______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
_______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
On 4 May 2015, at 12:46 pm, Naveed Massjouni <naveed@vt.edu> wrote:
What version of the DBIC plugin are you using? If you are not using the latest, can you upgrade and let me know if you still get the same warning.
Hi Naveed, I am using 0.0009 which I believe is the latest. Now that I have put Andy’s work around in I only get the DEPRECATED massage on startup, not each time the global is used: DEPRECATED: QTechLib::Plugin calls 'dsl' instead of '$dsl->dsl'. at /perf/perl/lib/perl5/Dancer2/Plugin/DBIC.pm line 13. DEPRECATED: QTechLib::Plugin calls 'dsl' instead of '$dsl->dsl'. at /perf/perl/lib/perl5/Dancer2/Plugin/DBIC.pm line 13. DEPRECATED: QTechLib::Plugin calls 'dsl' instead of '$dsl->dsl'. at /perf/perl/lib/perl5/Dancer2/Plugin/DBIC.pm line 13. DEPRECATED: QTechLib::Plugin calls 'dsl' instead of '$dsl->dsl'. at /perf/perl/lib/perl5/Dancer2/Plugin/DBIC.pm line 13. DEPRECATED: QTechLib::Plugin calls 'dsl' instead of '$dsl->dsl'. at /perf/perl/lib/perl5/Dancer2/Plugin/DBIC.pm line 13. 2015/05/04-18:44:16 Starman::Server (type Net::Server::PreFork) starting! pid(94405) Resolved [*]:3004 to [0.0.0.0]:3004, IPv4 Binding to TCP port 3004 on host 0.0.0.0 with IPv4 Setting gid to "1000 1000 10 1000" Starman: Accepting connections at http://*:3004/ (My plugin gets loaded multiple times as it’s referenced in multiple files making up my app.) And here’s the work around code in my plugin: my $schema; on_plugin_import { my $dsl = shift; # Grab a handle to the Plugin::DBIC schema die "No schema method in app. Did you load DBIC::Plugin::DBIC before QTechLib::Plugin?" unless $dsl->can('schema'); $schema = $dsl->schema; $dsl->debug( "**** Got Schema **** "); }; Let me know if you need more info. Thanks for the plugin! Cheers, Matt
participants (4)
-
Andrew Beverley -
Matthew Mallard -
Matthew Mallard -
Naveed Massjouni