Просмотр исходного кода

Merge pull request #371 from Troglodyne-Internet-Widgets/vestigial

Delete the code tPSGI made vestigial, and enable ProhibitUnusedDefinitions
George S. Baugh 1 неделя назад
Родитель
Сommit
0227d1935e
9 измененных файлов с 21 добавлено и 220 удалено
  1. 13 3
      .perlcriticrc
  2. 0 1
      Makefile.PL
  3. 1 2
      design.md
  4. 0 13
      lib/Trog/Auth.pm
  5. 0 26
      lib/Trog/Renderer/javascript.pm
  6. 0 65
      lib/Trog/Routes/TXT.pm
  7. 4 42
      lib/Trog/Themes.pm
  8. 3 13
      t/Trog-Themes-themed-templates.t
  9. 0 55
      www/templates/text/zone.tx

+ 13 - 3
.perlcriticrc

@@ -124,8 +124,18 @@ allow = re Exporter
 # them, or called only from a directory it does not read.  Name each one and say
 # them, or called only from a directory it does not read.  Name each one and say
 # which, so the next person can tell an exemption from an oversight.
 # which, so the next person can tell an exemption from an oversight.
 #
 #
-#[ProhibitUnusedDefinitions]
-#allow_subs =
+[ProhibitUnusedDefinitions]
+# tCMS:
+#   generic_route, @routes, %aliases  tPSGI reads them out of the router package
+#   aliases (both models)              TCMS::aliases calls $data->aliases, and
+#                                      the policy takes a method call from a sub
+#                                      of the same name for recursion
+#   posts, order                       named by a post type's x-tcms-datasource
+#   enrich                             named by a post type's sidecar
+#   create_statement, log_message      Log::Dispatch calls them
+#   series, users                      a post's callback names them
+allow_subs = TCMS::generic_route Trog::Data::FlatFile::aliases Trog::DataModule::aliases Trog::DataSource::DirIndex::posts Trog::DataSource::DirIndex::order Trog::DataSource::ProvisionedVirt::posts Trog::Enrich::Invoice::enrich Trog::Log::DBI::create_statement Trog::Log::DBI::log_message Trog::Log::Syslog::log_message Trog::Routes::HTML::series Trog::Routes::HTML::users
+allow_globals = @TCMS::routes %TCMS::aliases
 # A sub that only one subclass uses, and a sub that two subclasses define where
 # A sub that only one subclass uses, and a sub that two subclasses define where
 # the class above them defines none.  It reads bin/ and lib/ through
 # the class above them defines none.  It reads bin/ and lib/ through
 # Perl::Critic::Distribution, as ProhibitUnusedDefinitions does, so the two
 # Perl::Critic::Distribution, as ProhibitUnusedDefinitions does, so the two
@@ -226,7 +236,7 @@ exclude_functions = print say
 # tCMS: each renderer is named for the content type it renders, and each
 # tCMS: each renderer is named for the content type it renders, and each
 # script's package for the script.  The policy tests each part of a package
 # script's package for the script.  The policy tests each part of a package
 # name on its own, so these are the parts.
 # name on its own, so these are the parts.
-package_exemptions = main tcms login useradd blob css email html javascript json text
+package_exemptions = main tcms login useradd blob css email html json text
 [RegularExpressions::ProhibitCaptureWithoutTest]
 [RegularExpressions::ProhibitCaptureWithoutTest]
 [RegularExpressions::ProhibitComplexRegexes]
 [RegularExpressions::ProhibitComplexRegexes]
 [RegularExpressions::ProhibitEnumeratedClasses]
 [RegularExpressions::ProhibitEnumeratedClasses]

+ 0 - 1
Makefile.PL

@@ -133,7 +133,6 @@ WriteMakefile(
         'WWW::Sitemap::XML'                   => '0',
         'WWW::Sitemap::XML'                   => '0',
         'WWW::SitemapIndex::XML'              => '0',
         'WWW::SitemapIndex::XML'              => '0',
         'CSS::Minifier::XS'                   => '0',
         'CSS::Minifier::XS'                   => '0',
-        'JavaScript::Minifier::XS'            => '0',
         'Path::Tiny'                          => '0',
         'Path::Tiny'                          => '0',
         'Log::Dispatch'                       => '0',
         'Log::Dispatch'                       => '0',
         'Log::Dispatch::FileRotate'           => '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->render(%options)` dispatches on content type to a renderer under
 `Trog::Renderer::`, all of which subclass `Trog::Renderer::Base`. The known types
 `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,
 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
 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
 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;
     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
 =head2 get_existing_user_data
 
 
 Fetch existing settings for a user.
 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";
     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)
 =head2 dir_for($path, $content_type, $is_component)
 
 
 The single directory which owns a given component subdir: the theme's if it has
 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 ];
     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)
 =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
 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().
 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"
         "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";
     $themedir = "$root/www/themes/spec";
 
 
     is_deeply(
     is_deeply(
@@ -54,14 +52,6 @@ subtest 'with a partial theme, the two disagree' => sub {
         "the theme is searched first, then the stock tree"
         "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(
     is_deeply(
         [ sort @{ Trog::Themes::themed_templates_in_dir( 'forms', 'text/html', 1 ) } ],
         [ sort @{ Trog::Themes::themed_templates_in_dir( 'forms', 'text/html', 1 ) } ],
         [qw{blog.tx gallery.tx profile.tx series.tx}],
         [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"