<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 &lt;dave@dave.org.uk&gt; 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&nbsp; <br>reference to adding "schema components"[1] to the generated classes.&nbsp; <br>But I can't find any documentation on how you might write such a&nbsp; <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&nbsp; <br>schema component. Please either tell me that I'm wrong, or gently&nbsp; <br>nudge me in the right direction.<br><br>Here's what I want to do. Recently I've found myself adding a useful&nbsp; <br>"get_schema()" method to many of my schema classes. It looks something&nbsp; <br>like this:<br><br>sub get_schema {<br>&nbsp;  my @errs;<br><br>&nbsp;  foreach (qw[XXX_DB XXX_DB_USER XXX_DB_PASS XXX_DB_HOST]) {<br>&nbsp; &nbsp;  push @errs, $_ unless defined $ENV{$_};<br>&nbsp;  }<br>&nbsp;  if (@errs) {<br>&nbsp; &nbsp;  croak "You need to set the following environment variables: @errs\n";<br>&nbsp;  }<br><br>&nbsp;  return __PACKAGE__-&gt;connect(<br>&nbsp; &nbsp;  "dbi:mysql:database=$ENV{XXX_DB};host=$ENV{XXX_DB_HOST}",<br>&nbsp; &nbsp;  $ENV{XXX_DB_USER}, $ENV{XXX_DB_PASS},<br>&nbsp; &nbsp;  { mysql_enable_utf8 =&gt; 1 }<br>&nbsp;  );<br>}<br><br>The "XXX" is a placeholder for some prefix that is meaningful to&nbsp; <br>whatever schema I'm working with and it will change with each project&nbsp; <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&nbsp; <br>what a Bad Idea that is. And a schema component seemed a&nbsp; <br>likely-looking approach for getting round that. I thought I could&nbsp; <br>write DBIx::Class::Component::GetSchema which adds the method to any&nbsp; <br>schema class that loads it.<br><br>But, as I said above, I can't find any explanations or examples of&nbsp; <br>schema components that I can steal from.<br><br>Does anyone have any suggestions?<br><br>Cheers,<br><br>Dave...<br><br>[1]&nbsp; <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>