<html><head></head><body><div style="color:#000; background-color:#fff; font-family:Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:16px"><div id="yui_3_16_0_ym19_1_1473930204028_144781">Hi Dave,</div><div id="yui_3_16_0_ym19_1_1473930204028_144682"><br></div><div id="yui_3_16_0_ym19_1_1473930204028_144714" dir="ltr">Ah, right - I see what you mean. Maybe this is more what you're looking for: <a id="yui_3_16_0_ym19_1_1473930204028_144713" href="https://metacpan.org/pod/DBIx::Class::Helper::Schema::DateTime">https://metacpan.org/pod/DBIx::Class::Helper::Schema::DateTime</a>? Looking at the source it looks like the only special thing it really does is inherit from DBIx::Class::Schema.</div><div id="yui_3_16_0_ym19_1_1473930204028_144885" dir="ltr"><br></div><div dir="ltr">HTH,</div><div dir="ltr">Darius<br></div><div id="yui_3_16_0_ym19_1_1473930204028_144603"><span></span></div> <div class="qtdSeparateBR"><br><br></div><div style="display: block;" class="yahoo_quoted"> <div style="font-family: Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 16px;"> <div style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, Sans-Serif; font-size: 16px;"> <div dir="ltr"><font face="Arial" size="2"> On Tuesday, 20 September 2016, 12:11, Dave Cross <dave@dave.org.uk> wrote:<br></font></div> <blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; margin-top: 5px; padding-left: 5px;"> <br><br> <div class="y_msg_container"><br clear="none">Hi Darius,<br clear="none"><br clear="none">Thanks. Yes, I'd seen that documentation. It's a little sparse and <br clear="none">seems to be aimed at writing components which are loaded into Result <br clear="none">classes (InflateColumn::DateTime, TimeStamp and stuff like that). I <br clear="none">suspect (but I could, of course, be wrong) that components which are <br clear="none">loaded into Schema objects would follow different rules.<br clear="none"><br clear="none">Cheers,<br clear="none"><br clear="none">Dave...<br clear="none"><br clear="none">Quoting Darius Jokilehto <<a shape="rect" ymailto="mailto:dariusjokilehto@yahoo.co.uk" href="mailto:dariusjokilehto@yahoo.co.uk">dariusjokilehto@yahoo.co.uk</a>>:<br clear="none"><br clear="none">> Hello Dave,<br clear="none">> This might be what you're looking for: <br clear="none">> <a shape="rect" href="https://metacpan.org/pod/distribution/DBIx-Class/lib/DBIx/Class/Manual/Component.pod" target="_blank">https://metacpan.org/pod/distribution/DBIx-Class/lib/DBIx/Class/Manual/Component.pod</a><br clear="none">> Darius<br clear="none">><br clear="none">> On Friday, 16 September 2016, 17:09, Dave Cross <<a shape="rect" ymailto="mailto:dave@dave.org.uk" href="mailto:dave@dave.org.uk">dave@dave.org.uk</a>> wrote:<br clear="none">><br clear="none">> In the documentation of DBIx::Class::Schema::Loader::Base there is a <br clear="none">> reference to adding "schema components"[1] to the generated classes. <br clear="none">> But I can't find any documentation on how you might write such a <br clear="none">> component - or any clearly-labelled examples of a schema component.<br clear="none">><br clear="none">> I think I have an example of something that I'd like to write as a <br clear="none">> schema component. Please either tell me that I'm wrong, or gently <br clear="none">> nudge me in the right direction.<br clear="none">><br clear="none">> Here's what I want to do. Recently I've found myself adding a useful <br clear="none">> "get_schema()" method to many of my schema classes. It looks something <br clear="none">> like this:<br clear="none">><br clear="none">> sub get_schema {<br clear="none">> my @errs;<br clear="none">><br clear="none">> foreach (qw[XXX_DB XXX_DB_USER XXX_DB_PASS XXX_DB_HOST]) {<br clear="none">> push @errs, $_ unless defined $ENV{$_};<br clear="none">> }<br clear="none">> if (@errs) {<br clear="none">> croak "You need to set the following environment variables: @errs\n";<br clear="none">> }<br clear="none">><br clear="none">> return __PACKAGE__->connect(<br clear="none">> "dbi:mysql:database=$ENV{XXX_DB};host=$ENV{XXX_DB_HOST}",<br clear="none">> $ENV{XXX_DB_USER}, $ENV{XXX_DB_PASS},<br clear="none">> { mysql_enable_utf8 => 1 }<br clear="none">> );<br clear="none">> }<br clear="none">><br clear="none">> The "XXX" is a placeholder for some prefix that is meaningful to <br clear="none">> whatever schema I'm working with and it will change with each project <br clear="none">> (as will, potentially, the DBD name and the options hash).<br clear="none">><br clear="none">> I've been copying the code into my schema classes, but we all know <br clear="none">> what a Bad Idea that is. And a schema component seemed a <br clear="none">> likely-looking approach for getting round that. I thought I could <br clear="none">> write DBIx::Class::Component::GetSchema which adds the method to any <br clear="none">> schema class that loads it.<br clear="none">><br clear="none">> But, as I said above, I can't find any explanations or examples of <br clear="none">> schema components that I can steal from.<br clear="none">><br clear="none">> Does anyone have any suggestions?<br clear="none">><br clear="none">> Cheers,<br clear="none">><br clear="none">> Dave...<br clear="none">><br clear="none">> [1] <br clear="none">> <a shape="rect" href="https://metacpan.org/pod/DBIx::Class::Schema::Loader::Base#schema_components" target="_blank">https://metacpan.org/pod/DBIx::Class::Schema::Loader::Base#schema_components</a><br clear="none">><br clear="none">><br clear="none">><br clear="none">> _______________________________________________<br clear="none">> List: <a shape="rect" href="http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class" target="_blank">http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class</a><br clear="none">> IRC: irc.perl.org#dbix-class<br clear="none">> SVN: <a shape="rect" href="http://dev.catalyst.perl.org/repos/bast/DBIx-Class/" target="_blank">http://dev.catalyst.perl.org/repos/bast/DBIx-Class/</a><br clear="none">> Searchable Archive: <br clear="none">> <a shape="rect" href="http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk" target="_blank">http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk</a><div class="yqt4230965900" id="yqtfd89530"><br clear="none"><br clear="none"><br clear="none"><br clear="none"><br clear="none">_______________________________________________<br clear="none">List: <a shape="rect" href="http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class" target="_blank">http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class</a><br clear="none">IRC: irc.perl.org#dbix-class<br clear="none">SVN: <a shape="rect" href="http://dev.catalyst.perl.org/repos/bast/DBIx-Class/" target="_blank">http://dev.catalyst.perl.org/repos/bast/DBIx-Class/</a><br clear="none">Searchable Archive: <a shape="rect" href="http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk" target="_blank">http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk</a></div><br><br></div> </blockquote> </div> </div> </div></div></body></html>