Browse Source

Delete the code that nothing reaches since tPSGI took over serving

Each of these lost its last caller and stayed behind:

- Trog::Routes::TXT and zone.tx.  TCMS builds its routing table from the
  HTML and JSON routers only, so /text/zone was never served, and the zone
  template had no other reader.
- Trog::Renderer::javascript, which the renderer table never named, and
  with it the JavaScript::Minifier::XS prerequisite that only it used.
- Trog::Auth::primary_user, whose only caller went with bin/build_zone.
- Trog::Themes::themed_template, uncalled since the render refactor.
- Trog::Themes::templates_in_dir and files_in_dir.  themed_templates_in_dir
  replaced them in every caller, because a theme's own forms/ dir hid every
  stock post type from them.  The theme test compared the two helpers, so
  it now asserts what themed_templates_in_dir lists.

Found by ProhibitUnusedDefinitions over bin/ and lib/, and by a search for
modules that no file in bin, lib, t or www names.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
troglodyne-bot 1 week ago
parent
commit
0486377800

+ 0 - 1
Makefile.PL

@@ -133,7 +133,6 @@ WriteMakefile(
         'WWW::Sitemap::XML'                   => '0',
         'WWW::SitemapIndex::XML'              => '0',
         'CSS::Minifier::XS'                   => '0',
-        'JavaScript::Minifier::XS'            => '0',
         'Path::Tiny'                          => '0',
         'Log::Dispatch'                       => '0',
         'Log::Dispatch::FileRotate'           => '0',

+ 1 - 2
design.md

@@ -328,8 +328,7 @@ Rendering
 `Trog::Renderer->render(%options)` dispatches on content type to a renderer under
 `Trog::Renderer::`, all of which subclass `Trog::Renderer::Base`. The known types
 are in `Trog::Vars::%content_types`: text, html, json, blob, xml, xsl, css, rss,
-email. (`Trog::Renderer::javascript` exists but is not registered in the
-dispatcher.)
+email.
 
 Base sets up the Xslate instance, resolves templates against the theme's
 directory and then the stock one, and injects two functions every template can

+ 0 - 13
lib/Trog/Auth.pm

@@ -77,19 +77,6 @@ sub user_exists ($user) {
     return 1;
 }
 
-=head2 primary_user
-
-Returns the oldest user with the admin ACL.
-
-=cut
-
-sub primary_user {
-    my $dbh  = dbh();
-    my $rows = $dbh->selectall_arrayref( "SELECT username FROM user_acl WHERE acl='admin' LIMIT 1", { Slice => {} } );
-    return 0 unless ref $rows eq 'ARRAY' && @$rows;
-    return $rows->[0]{username};
-}
-
 =head2 get_existing_user_data
 
 Fetch existing settings for a user.

+ 0 - 26
lib/Trog/Renderer/javascript.pm

@@ -1,26 +0,0 @@
-package Trog::Renderer::javascript;
-
-use 5.040;
-use re '/aasx';
-use warnings FATAL => 'all';
-
-use parent qw{Trog::Renderer::Base};
-
-use JavaScript::Minifier::XS;
-
-my sub minify {
-    return JavaScript::Minifier::XS::minify(shift);
-}
-
-=head1 Trog::Renderer::javascript
-
-Render JS, and minify the output.
-
-=cut
-
-sub render (%options) {
-    $options{post_processor} = \&minify;
-    return Trog::Renderer::Base::render(%options);
-}
-
-1;

+ 0 - 65
lib/Trog/Routes/TXT.pm

@@ -1,65 +0,0 @@
-package Trog::Routes::TXT;
-
-use 5.040;
-use re '/aasx';
-use warnings FATAL => 'all';
-
-use Trog::Renderer;
-
-our %routes = (
-    '/text/zone' => {
-        method     => 'GET',
-        callback   => \&zone,
-        parameters => {},
-        admin      => 1,
-    },
-);
-
-my sub _render ( $code, $headers, %data ) {
-    return Trog::Renderer->render(
-        code        => $code,
-        data        => \%data,
-        template    => 'zone.tx',
-        contenttype => 'text/plain',
-        headers     => $headers,
-    );
-}
-
-=head1 Trog::Routes::TXT
-
-Routes which render as text/plain.
-
-=head1 CAVEATS
-
-This module is not wired up to anything.  TCMS.pm builds its routing table out
-of Trog::Routes::HTML and Trog::Routes::JSON only, so nothing here is reachable
-and /text/zone will 404.
-
-=head1 VARIABLES
-
-=over 4
-
-=item %routes
-
-The usual tCMS routing table -- path to method, callback, parameters and
-whether the route requires admin.
-
-=back
-
-=head1 ROUTES
-
-=head2 zone
-
-Render zone.tx, this instance's DNS zone file.  Admin only.
-
-Note that it passes the query through as-is; zone.tx wants $ip, $nameservers,
-$subdomains and friends, so it needs a data gathering pass before it will
-render anything.
-
-=cut
-
-sub zone ($query) {
-    return _render( 200, {}, $query );
-}
-
-1;

+ 4 - 42
lib/Trog/Themes.pm

@@ -171,16 +171,6 @@ sub themed_script ($resource) {
     return dir_for_resource("scripts/$resource") . "/scripts/$resource";
 }
 
-=head2 themed_template($resource)
-
-Path to a template under www/templates, preferring the theme's copy.
-
-=cut
-
-sub themed_template ($resource) {
-    return dir_for_resource("templates/$resource") . "/templates/$resource";
-}
-
 =head2 dir_for($path, $content_type, $is_component)
 
 The single directory which owns a given component subdir: the theme's if it has
@@ -213,40 +203,12 @@ my sub read_dir ( $dir, $ext ) {
     return [ map { $_->basename } @files ];
 }
 
-=head2 files_in_dir($path, $content_type, $is_component, $ext)
-
-Bare filenames with the given extension in whichever single directory dir_for()
-picks.  See themed_templates_in_dir() for the version which spans both.
-
-=cut
-
-sub files_in_dir ( $path, $ct, $is_component = 0, $ext = 'tx' ) {
-    return read_dir( dir_for( $path, $ct, $is_component ), $ext );
-}
-
-=head2 templates_in_dir($path, $content_type, $is_component)
-
-files_in_dir() restricted to templates.
-
-Beware that this only ever reads one directory -- see themed_templates_in_dir()
-for why that's usually not what you want.
-
-=cut
-
-sub templates_in_dir ( $path, $ct, $is_component = 0 ) {
-    return files_in_dir( $path, $ct, $is_component, 'tx' );
-}
-
 =head2 themed_templates_in_dir($path, $content_type, $is_component)
 
-Same calling convention as templates_in_dir(), but it doesn't make you pick a
-side: you get the theme's templates where the theme has them, plus the stock
-ones it hasn't overridden.
-
-templates_in_dir() resolves through template_dir(), which is winner-take-all --
-if a theme has a forms/ dir at all, its contents are the *only* post types the
-site can see, and every core one vanishes.  That's rarely what a theme author
-means by overriding a template.
+The template names in an abstract template dir, from the theme and the stock
+tree both: the theme's templates where the theme has them, plus the stock ones
+it hasn't overridden.  dir_for() is winner-take-all, so a theme with a forms/
+dir of its own would otherwise hide every core post type.
 
 Returns bare filenames, deduped, theme first.  Which of the two files a given
 name resolves to is then up to whoever renders it -- see template_dirs().

+ 3 - 13
t/Trog-Themes-themed-templates.t

@@ -39,13 +39,11 @@ subtest 'with no theme, nothing changes' => sub {
         "only the stock dir is searched"
     );
 
-    my $old = [ sort @{ Trog::Themes::templates_in_dir( 'forms', 'text/html', 1 ) } ];
-    my $new = [ sort @{ Trog::Themes::themed_templates_in_dir( 'forms', 'text/html', 1 ) } ];
-    is_deeply( $new, $old,                               "the themed helper agrees with the old one" );
-    is_deeply( $new, [qw{blog.tx profile.tx series.tx}], "...and lists the stock templates" );
+    my $listed = [ sort @{ Trog::Themes::themed_templates_in_dir( 'forms', 'text/html', 1 ) } ];
+    is_deeply( $listed, [qw{blog.tx profile.tx series.tx}], "the stock templates are listed" );
 };
 
-subtest 'with a partial theme, the two disagree' => sub {
+subtest 'with a partial theme, the stock templates show through' => sub {
     $themedir = "$root/www/themes/spec";
 
     is_deeply(
@@ -54,14 +52,6 @@ subtest 'with a partial theme, the two disagree' => sub {
         "the theme is searched first, then the stock tree"
     );
 
-    # This is the shortcoming: one forms/ dir in a theme hides every stock
-    # post type the theme didn't happen to copy.
-    is_deeply(
-        [ sort @{ Trog::Themes::templates_in_dir( 'forms', 'text/html', 1 ) } ],
-        [qw{blog.tx gallery.tx}],
-        "templates_in_dir() sees only the theme's"
-    );
-
     is_deeply(
         [ sort @{ Trog::Themes::themed_templates_in_dir( 'forms', 'text/html', 1 ) } ],
         [qw{blog.tx gallery.tx profile.tx series.tx}],

+ 0 - 55
www/templates/text/zone.tx

@@ -1,55 +0,0 @@
-$TTL    300
-
-@       IN      SOA     <: $title :>. soa.<: $title :>. (
-                        <: $version :> ; Serial
-                        10800   ; Refresh
-                        3600    ; Retry
-                        604800  ; Expire
-                        10800 ) ; Minimum
-
-; NS Records.
-; These are actually academic, as the registrar is where any of this matters.
-; You'll have to also set up A / AAAA records with the IP of these NS subdos of yours.
-: for $nameservers -> $ns {
-<: $title :>. IN NS <: $ns :>.
-: }
-
-; A Records
-<: $title :>. IN A <: $ip :>
-<: $title :>. IN AAAA <: $ip6 :>
-
-; PTR - also academic.  Must be set not with your registrar, but your ISP/colo etc.
-<: $ip_reversed :> IN PTR <: $title :>
-<: $ip6_reversed :>    IN PTR <: $title :>
-
-; Subtitles. Look ma, it's a glue record!
-: for $subdomains -> $sub {
-<: $sub.name :>.<: $title :>. IN A    <: $sub.ip :>
-<: $sub.name :>.<: $title :>. IN AAAA <: $sub.ip6 :>
-:     for $sub.nameservers -> $ns {
-<: $sub.name :>.<: $title :>. IN NS   <: $ns :>
-:     }
-: }
-
-; CNAME records
-: for $cnames -> $cname {
-<: $cname :>.<: $title :>. IN CNAME <: $title :>.
-: }
-
-; MX & SRV records
-<: $title :>.    IN MX  0 mail.<: $title :>.
-_smtps._tcp.mail.<: $title :>. IN SRV 10 5 587 .
-_imaps._tcp.mail.<: $title :>. IN SRV 10 5 993 .
-_pop3s._tcp.mail.<: $title :>. IN SRV 10 5 995 .
-
-; SPF, DKIM, DMARC
-_dmarc.<: $title :>.          IN TXT "v=DMARC1; p=reject; rua=mailto:postmaster@<: $title :>; ruf=mailto:postmaster@<: $title :>"
-mail._domainkey.<: $title :>. IN TXT "v=DKIM1; h=sha256; k=rsa; t=y; p=<: $dkim_pkey :>"
-<: $title :>.                 IN TXT "v=spf1 +mx +a +ip4:<: $ip :> +ip6:<: $ip6 :> ~all"
-
-; Indexer verification
-<: $title :>.                 IN TXT "google-site-verification=<: $gsv_string :>"
-
-; LetsEncyst
-_acme-challenge.<: $title :>. IN TXT  "<: $acme_challenge :>"
-<: $title :>.                 IN CAA 0 issue "letsencrypt.org"