<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_105064">Hello Dave,</div><div id="yui_3_16_0_ym19_1_1473930204028_104989"><br></div><div dir="ltr" id="yui_3_16_0_ym19_1_1473930204028_104986">This might be what you're looking for: <a id="yui_3_16_0_ym19_1_1473930204028_104988" href="https://metacpan.org/pod/distribution/DBIx-Class/lib/DBIx/Class/Manual/Component.pod">https://metacpan.org/pod/distribution/DBIx-Class/lib/DBIx/Class/Manual/Component.pod</a></div><div dir="ltr"><br></div><div id="yui_3_16_0_ym19_1_1473930204028_105070" dir="ltr">Darius<br></div><div id="yui_3_16_0_ym19_1_1473930204028_104985"><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 Friday, 16 September 2016, 17:09, 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>In the documentation of DBIx::Class::Schema::Loader::Base there is a <br>reference to adding "schema components"[1] to the generated classes. <br>But I can't find any documentation on how you might write such a <br>component - or any clearly-labelled examples of a schema component.<br><br>I think I have an example of something that I'd like to write as a <br>schema component. Please either tell me that I'm wrong, or gently <br>nudge me in the right direction.<br><br>Here's what I want to do. Recently I've found myself adding a useful <br>"get_schema()" method to many of my schema classes. It looks something <br>like this:<br><br>sub get_schema {<br> my @errs;<br><br> foreach (qw[XXX_DB XXX_DB_USER XXX_DB_PASS XXX_DB_HOST]) {<br> push @errs, $_ unless defined $ENV{$_};<br> }<br> if (@errs) {<br> croak "You need to set the following environment variables: @errs\n";<br> }<br><br> return __PACKAGE__->connect(<br> "dbi:mysql:database=$ENV{XXX_DB};host=$ENV{XXX_DB_HOST}",<br> $ENV{XXX_DB_USER}, $ENV{XXX_DB_PASS},<br> { mysql_enable_utf8 => 1 }<br> );<br>}<br><br>The "XXX" is a placeholder for some prefix that is meaningful to <br>whatever schema I'm working with and it will change with each project <br>(as will, potentially, the DBD name and the options hash).<br><br>I've been copying the code into my schema classes, but we all know <br>what a Bad Idea that is. And a schema component seemed a <br>likely-looking approach for getting round that. I thought I could <br>write DBIx::Class::Component::GetSchema which adds the method to any <br>schema class that loads it.<br><br>But, as I said above, I can't find any explanations or examples of <br>schema components that I can steal from.<br><br>Does anyone have any suggestions?<br><br>Cheers,<br><br>Dave...<br><br>[1] <br><a 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><br><br><br>_______________________________________________<br>List: <a 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>IRC: irc.perl.org#dbix-class<br>SVN: <a href="http://dev.catalyst.perl.org/repos/bast/DBIx-Class/" target="_blank">http://dev.catalyst.perl.org/repos/bast/DBIx-Class/</a><br>Searchable Archive: <a 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><br><br><br></div> </blockquote> </div> </div> </div></div></body></html>