[Jifty-commit] r5226 - in Net-Jifty: . t
Jifty commits
jifty-commit at lists.jifty.org
Mon Mar 17 14:01:20 EDT 2008
Author: sartak
Date: Mon Mar 17 14:01:19 2008
New Revision: 5226
Modified:
Net-Jifty/ (props changed)
Net-Jifty/Changes
Net-Jifty/lib/Net/Jifty.pm
Net-Jifty/t/005-validate.t
Log:
r52740 at onn: sartak | 2008-03-17 14:01:01 -0400
Cache each action spec
Modified: Net-Jifty/Changes
==============================================================================
--- Net-Jifty/Changes (original)
+++ Net-Jifty/Changes Mon Mar 17 14:01:19 2008
@@ -1,5 +1,8 @@
Revision history for Net-Jifty
+0.07
+ Cache each action spec
+
0.06 Mon Mar 17 13:15:09
Add directory filters for use by applications and subclasses
Basically, each directory in your path can have a .jifty file
Modified: Net-Jifty/lib/Net/Jifty.pm
==============================================================================
--- Net-Jifty/lib/Net/Jifty.pm (original)
+++ Net-Jifty/lib/Net/Jifty.pm Mon Mar 17 14:01:19 2008
@@ -185,6 +185,13 @@
documentation => "Check to make sure mandatory arguments are provided, and no unknown arguments are included",
);
+has action_specs => (
+ is => 'rw',
+ isa => 'HashRef[HashRef]',
+ default => sub { {} },
+ documentation => "The cache for action specifications",
+);
+
=head2 BUILD
Each L<Net::Jifty> object will do the following upon creation:
@@ -538,11 +545,11 @@
$name = $action;
}
- my $action_args = $self->get("action/$name");
+ my $action_spec = $self->get_action_spec($name);
- for my $arg (keys %$action_args) {
+ for my $arg (keys %$action_spec) {
confess "Mandatory argument '$arg' not given for action $name."
- if $action_args->{$arg}{mandatory} && !defined($args{$arg});
+ if $action_spec->{$arg}{mandatory} && !defined($args{$arg});
delete $args{$arg};
}
@@ -554,6 +561,25 @@
return 1;
}
+=head2 get_action_spec action_name
+
+Returns the action spec (which arguments it takes, and metadata about them).
+The first request for a particular action will ask the server for the spec.
+Subsequent requests will return it from the cache.
+
+=cut
+
+sub get_action_spec {
+ my $self = shift;
+ my $name = shift;
+
+ unless ($self->action_specs->{$name}) {
+ $self->action_specs->{$name} = $self->get("action/$name");
+ }
+
+ return $self->action_specs->{$name};
+}
+
=head2 get_sid
Retrieves the sid from the L<LWP::UserAgent> object.
Modified: Net-Jifty/t/005-validate.t
==============================================================================
--- Net-Jifty/t/005-validate.t (original)
+++ Net-Jifty/t/005-validate.t Mon Mar 17 14:01:19 2008
@@ -1,7 +1,7 @@
#!/usr/bin/env perl
use strict;
use warnings;
-use Test::More tests => 20;
+use Test::More tests => 31;
use lib 't/lib';
use Net::Jifty::Test;
@@ -25,6 +25,7 @@
is($name, 'get', 'used get for validation');
is($args->[1], 'http://jifty.org/=/action/CreateFoo.yml', 'correct URL');
$j->ua->clear;
+ok(delete $j->action_specs->{"CreateFoo"}, "cached spec");
$Net::Jifty::Test::content = << "YAML";
---
@@ -39,6 +40,7 @@
is($name, 'get', 'used get for validation');
is($args->[1], 'http://jifty.org/=/action/CreateFoo.yml', 'correct URL');
$j->ua->clear;
+ok(delete $j->action_specs->{"CreateFoo"}, "cached spec");
$Net::Jifty::Test::content = << "YAML";
---
@@ -57,6 +59,7 @@
is($name, 'get', 'used get for validation');
is($args->[1], 'http://jifty.org/=/action/CreateFoo.yml', 'correct URL');
$j->ua->clear;
+ok(delete $j->action_specs->{"CreateFoo"}, "cached spec");
$Net::Jifty::Test::content = << "YAML";
---
@@ -72,6 +75,7 @@
is($name, 'get', 'used get for validation');
is($args->[1], 'http://jifty.org/=/action/CreateFoo.yml', 'correct URL');
$j->ua->clear;
+ok(delete $j->action_specs->{"CreateFoo"}, "cached spec");
$j = Net::Jifty::Test->new(strict_arguments => 1);
@@ -88,6 +92,7 @@
is($name, 'get', 'used get for validation');
is($args->[1], 'http://jifty.org/=/action/CreateFoo.yml', 'correct URL');
$j->ua->clear;
+ok(delete $j->action_specs->{"CreateFoo"}, "cached spec");
$Net::Jifty::Test::content = << "YAML";
---
@@ -99,6 +104,7 @@
($name, $args) = $j->ua->next_call;
is($name, 'get', 'used get for validation');
is($args->[1], 'http://jifty.org/=/action/CreateFoo.yml', 'correct URL');
+ok($j->action_specs->{"CreateFoo"}, "cached spec");
($name, $args) = $j->ua->next_call;
is($name, 'request', 'used request for create');
@@ -109,3 +115,13 @@
$j->ua->clear;
+$j->create("Jifty::Model::Foo", %args);
+($name, $args) = $j->ua->next_call;
+is($name, 'request', 'used cache version of action spec');
+isa_ok($args->[1], 'HTTP::Request', 'argument is an HTTP request');
+is($args->[1]->method, 'POST', 'correct method (POST)');
+is($args->[1]->uri, 'http://jifty.org/=/model/Jifty%3A%3AModel%3A%3AFoo.yml', 'correct URL');
+like($args->[1]->content, qr/^(a=b&c=d|c=d&a=b)$/, 'correct arguments');
+
+$j->ua->clear;
+
More information about the Jifty-commit
mailing list