App-Netdisco

 view release on metacpan or  search on metacpan

xt/lib/Test/Netdisco/Snapshot.pm  view on Meta::CPAN

        is_discoverable => 1, is_arpnipable => 1, is_macsuckable => 0,
      },
      filtered_tags => ['core'],
    };
  }

  if ($view eq 'ajax/admintask/jobqueue.tt') {
    return {
      results => [
        { job => 1, backend => 'localhost', action => 'discover',
          status => 'queued', username => 'demo', duration => '5s' },
      ],
    };
  }

  if ($view eq 'ajax/admintask/acleditor.tt') {
    my @pairs = ( {
      id => 1,
      left_acl_with_dns => { ruleset => [ [ '192.0.2.0/24' ] ] },
      right_acl => { rules => ['80'] },
    } );
    return {
      acl_name => 'demo',
      params => { acl_type => 'host_port' },
      # production's `results` is a DBIx::Class::ResultSet, walked with
      # results.next rather than FOREACH; a coderef reproduces just that
      results => { next => sub { shift @pairs } },
    };
  }

  if ($view eq 'ajax/admintask/aclmanager.tt') {
    return { results => [ { acl_name => 'demo', acl_type => 'host' } ] };
  }

  if ($view eq 'index.tt') {
    return {
      session => { logged_in_user => 'demo' },
      # stubbed true to reach the Admin discovery form
      user_has_role => sub { 1 },
      params => { login_failed => 1 },
      vars => { notfound => 1 },
    };
  }

  return {};
}

=head2 render_template( $relative_path )

Returns C<($html, undef)> on success or C<(undef, $error)> on failure.

=cut

sub render_template {
  my $view = shift;
  my $engine = _engine();
  my $out = '';
  # Templates read empty values from the stash; that is expected here and the
  # resulting numeric warnings are noise, not signal.
  local $SIG{__WARN__} = sub { };
  # Mirrors lib/App/Netdisco/Web.pm:404, which the application sets before
  # every render so settings._foo keys resolve instead of being hidden by
  # Template::Stash's leading-underscore filter. This must run after the
  # _engine() call above: that call is what first loads Template::Stash and
  # assigns its qr/^[_.]/ default, so setting this beforehand would only be
  # overwritten by that load. Localized to this one process() call so the
  # package global cannot leak into another subtest in this process.
  local $Template::Stash::PRIVATE = undef;
  if ($engine->process($view, stash_for($view), \$out)) {
    return ($out, undef);
  }
  return (undef, scalar $engine->error);
}

=head2 snapshot_path( $relative_path )

Where the committed snapshot for a template lives.

=cut

sub snapshot_path {
  my $view = shift;
  return join '/', SNAPSHOT_ROOT, $view . '.html';
}

1;



( run in 1.422 second using v1.01-cache-2.11-cpan-744e820c463 )