Mailing List Archive

[svn] r875 - in experiments/Bamboo: . lib/Bamboo lib/Bamboo/Controller lib/Bamboo/Model/ProxyObject/RT t
Author: jesse
Date: Wed May 12 02:20:54 2004
New Revision: 875

Added:
experiments/Bamboo/t/1basicparse.t
Modified:
experiments/Bamboo/ (props changed)
experiments/Bamboo/lib/Bamboo/Controller.pm
experiments/Bamboo/lib/Bamboo/Controller/Method.pm
experiments/Bamboo/lib/Bamboo/Controller/MethodCollection.pm
experiments/Bamboo/lib/Bamboo/Controller/Object.pm
experiments/Bamboo/lib/Bamboo/Controller/ObjectCollection.pm
experiments/Bamboo/lib/Bamboo/Controller/ParamCollection.pm
experiments/Bamboo/lib/Bamboo/Model/ProxyObject/RT/Queue.pm
Log:
----------------------------------------------------------------------
r1541@tinbook: jesse | 2004-05-12T06:20:13.570746Z

Tests! code!
----------------------------------------------------------------------


Modified: experiments/Bamboo/lib/Bamboo/Controller.pm
==============================================================================
--- experiments/Bamboo/lib/Bamboo/Controller.pm (original)
+++ experiments/Bamboo/lib/Bamboo/Controller.pm Wed May 12 02:20:54 2004
@@ -3,6 +3,7 @@
use strict;
use warnings;

+use Bamboo::Controller::ObjectCollection;
use base qw/Bamboo::Base/;
use CGI;

@@ -12,11 +13,11 @@
my $self = {};
bless( $self, $class );

- $self->{obj_cache} = Bamboo::Controller::ObjectCache->new();
+ $self->{obj_cache} = Bamboo::Controller::ObjectCollection->new();
return $self;
}

-sub parse_params_hash {
+sub parse_param_hash {
my $self = shift;
my %params = (@_);
while ((my $param, my $value) = each %params) {
@@ -27,10 +28,13 @@
my $method_moniker = $4;
my $param = $5;

- my $object = $self->get_object( $object_type, $object_moniker );
+
+
+ my $object = $self->{'obj_cache'}->get( $object_type, $object_moniker );
+
$object->add_method_param(
method => $method,
- method_moniker => $method_moniker,
+ moniker => $method_moniker,
param => $param,
value => $value
);
@@ -40,20 +44,6 @@
}
}

-sub get_object {
- my $self = shift;
- my $type = shift;
- my $moniker = shift;
- return $self->{'obj_cache'}->get($type, $moniker);
-}
-
-sub add_method_param {
- my $self = shift;
- my $object = shift;
- my $method = shift;
- my $param = shift;
-
-}

sub validate_method_calls {

@@ -63,8 +53,8 @@
sub process_method_calls {
my $self = shift;
#figure out which objects we have to look at
- foreach my $object ($self->objects_to_process()){
- foreach my $method ($self->methods_for_object($object)) {
+ foreach my $object ($self->objects->as_array()){
+ foreach my $method ($object->methods->as_array()) {
if ($self->validate_object_method($method,$object)){
$self->call_object_method($object, $method)
}
@@ -74,6 +64,10 @@
}


+sub objects {
+ my $self = shift;
+ return ($self->{obj_cache});
+}

sub objects_to_process {


Modified: experiments/Bamboo/lib/Bamboo/Controller/Method.pm
==============================================================================
--- experiments/Bamboo/lib/Bamboo/Controller/Method.pm (original)
+++ experiments/Bamboo/lib/Bamboo/Controller/Method.pm Wed May 12 02:20:54 2004
@@ -1,11 +1,12 @@
package Bamboo::Controller::Method;
-param;

use strict;
use warnings;

use base qw/Bamboo::Base/;

+use Bamboo::Controller::ParamCollection;
+
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
@@ -21,23 +22,18 @@

}

-
-sub add_param {
- my $self = shift;
- my $name = shift;
- my $value = shift;
-
- $self->{'params'}->add($name, $value);
-
+sub type {
+ $_[0]->{'type'};
+}


+sub moniker {
+ $_[0]->{'moniker'};
}

-sub get_param {
+sub params {
my $self = shift;
- my $param = shift;
-
-
+ return $self->{'params'};
}

1;

Modified: experiments/Bamboo/lib/Bamboo/Controller/MethodCollection.pm
==============================================================================
--- experiments/Bamboo/lib/Bamboo/Controller/MethodCollection.pm (original)
+++ experiments/Bamboo/lib/Bamboo/Controller/MethodCollection.pm Wed May 12 02:20:54 2004
@@ -5,13 +5,15 @@

use base qw/Bamboo::Base/;

+use Bamboo::Controller::Method;
+
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
my $self = {};
bless ($self, $class);

- $self->method_cache({});
+ $self->methods({});

return $self;
}
@@ -21,19 +23,25 @@
my $self = shift;
my $type = shift;
my $moniker = shift;
- unless ( $self->{'method_cache'}->{$type."-".$moniker}) {
- $self->{'method_cache'}->{$type."-".$moniker} = Bamboo::Controller::Method->new($type, $moniker);
+ my $id = "$type-$moniker";
+ unless ( $self->methods->{$id}) {
+ $self->methods->{$id} = Bamboo::Controller::Method->new($type, $moniker);

}
- return($self->{'method_cache'}->{$type."-".$moniker});
+ return($self->methods->{$id});
}


-sub method_cache {
+sub as_array {
+ my $self = shift;
+ return values %{$self->methods};
+}
+
+sub methods {
my $self = shift;

- $self->{'method_cache'} = shift if (@_);
- return($self->{'method_cache'});
+ $self->{'methods'} = shift if (@_);
+ return($self->{'methods'});

}


Modified: experiments/Bamboo/lib/Bamboo/Controller/Object.pm
==============================================================================
--- experiments/Bamboo/lib/Bamboo/Controller/Object.pm (original)
+++ experiments/Bamboo/lib/Bamboo/Controller/Object.pm Wed May 12 02:20:54 2004
@@ -5,6 +5,8 @@

use base qw/Bamboo::Base/;

+use Bamboo::Controller::MethodCollection;
+
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
@@ -19,20 +21,23 @@
return $self;

}
-
+sub methods {
+ my $self = shift;
+ return $self->{methods};
+}

sub add_method_param {
my $self = shift;
my %args = (
- name => undef,
- moniker => undef,
- param => undef,
+ name => '*unknown*',
+ moniker => '*unknown*',
+ param => '*unknown*',
value => undef,
@_
);

- my $method = $self->{'methods'}->get($args{'method'}, $args{'moniker'} );
- $method->add_param( $args{param}, $args{value});
+ my $method = $self->methods->get($args{'method'}, $args{'moniker'} );
+ $method->params->add( $args{param}, $args{value});
}

1;

Modified: experiments/Bamboo/lib/Bamboo/Controller/ObjectCollection.pm
==============================================================================
--- experiments/Bamboo/lib/Bamboo/Controller/ObjectCollection.pm (original)
+++ experiments/Bamboo/lib/Bamboo/Controller/ObjectCollection.pm Wed May 12 02:20:54 2004
@@ -3,6 +3,7 @@
use strict;
use warnings;

+use Bamboo::Controller::Object;
use base qw/Bamboo::Base/;

sub new {
@@ -11,7 +12,7 @@
my $self = {};
bless ($self, $class);

- $self->object_cache({});
+ $self->objects({});

return $self;
}
@@ -21,15 +22,15 @@
my $self = shift;
my $type = shift;
my $moniker = shift;
- unless ( $self->{'object_cache'}->{$type."-".$moniker}) {
- $self->{'object_cache'}->{$type."-".$moniker} = Bamboo::Controller::Object->new($type, $moniker);
+ unless ( $self->objects->{$type."-".$moniker}) {
+ $self->objects->{$type."-".$moniker} = Bamboo::Controller::Object->new($type, $moniker);

}
- return($self->{'object_cache'}->{$type."-".$moniker});
+ return($self->objects->{$type."-".$moniker});
}


-sub object_cache {
+sub objects {
my $self = shift;

$self->{'object_cache'} = shift if (@_);
@@ -37,4 +38,9 @@

}

+sub as_array {
+ my $self = shift;
+ return values %{$self->objects};
+}
+
1;

Modified: experiments/Bamboo/lib/Bamboo/Controller/ParamCollection.pm
==============================================================================
--- experiments/Bamboo/lib/Bamboo/Controller/ParamCollection.pm (original)
+++ experiments/Bamboo/lib/Bamboo/Controller/ParamCollection.pm Wed May 12 02:20:54 2004
@@ -11,6 +11,8 @@
my $self = {};
bless ($self, $class);

+ $self->{params} = {};
+
return $self;
}

@@ -20,17 +22,17 @@
my $param = shift;
my $value = shift;

- if ($self->{params}->{$param}) {
- if (ref($self->{params}->{$param}) eq 'ARRAY') {
+ if ($self->params->{$param}) {
+ if (ref($self->params->{$param}) eq 'ARRAY') {

- push @{$self->{params}->{$param}}, $value;
+ push @{$self->params->{$param}}, $value;
}
else {
- @{$self->{params}->{$param}} = [ $self->{params}->{$param}, $value ];
+ @{$self->params->{$param}} = [ $self->params->{$param}, $value ];
}

} else {
- $self->{params}->{$param} = $value;
+ $self->params->{$param} = $value;

}

@@ -50,13 +52,23 @@
sub delete {
my $self = shift;
my $param = shift;
- delete ($self->{'params'}->{$param});
+ delete ($self->params->{$param});
}

sub get {
my $self = shift;
my $param = shift;
- return($self->{params}->{$param});
+ return($self->params->{$param});
+}
+
+sub params {
+ my $self = shift;
+ return $self->{params};
}

+sub names {
+ my $self = shift;
+ return keys %{$self->params};
+
+}
1;

Modified: experiments/Bamboo/lib/Bamboo/Model/ProxyObject/RT/Queue.pm
==============================================================================
--- experiments/Bamboo/lib/Bamboo/Model/ProxyObject/RT/Queue.pm (original)
+++ experiments/Bamboo/lib/Bamboo/Model/ProxyObject/RT/Queue.pm Wed May 12 02:20:54 2004
@@ -5,6 +5,8 @@

use base qw/RT::Web::ProxyObject/;

+=begin block
+
my $_RENDERERS = {
id => { Render => 'integer' },
Name => { Render => 'scalar', Edit => 1 },
@@ -52,4 +54,6 @@
}
};

+=cut
+
1;

Added: experiments/Bamboo/t/1basicparse.t
==============================================================================
--- (empty file)
+++ experiments/Bamboo/t/1basicparse.t Wed May 12 02:20:54 2004
@@ -0,0 +1,27 @@
+use Test::More qw/no_plan/;
+
+use YAML qw/Dump/;
+use_ok(Bamboo::Controller);
+
+my %basic_test = (
+
+ 'RT::Ticket-23-SetStatus-ss1-_Param1' => 'open',
+ 'RT::Ticket-24-SetStatus-ss1-_Param1' => 'stalled',
+
+);
+
+
+my $controller = Bamboo::Controller->new();
+is(ref($controller), 'Bamboo::Controller');
+$controller->parse_param_hash(%basic_test);
+is(ref($controller->objects), 'Bamboo::Controller::ObjectCollection');
+
+my @objects =$controller->objects->as_array;
+is ($#objects, 1);
+my @methods = $objects[0]->methods->as_array;
+is ($#methods,0);
+my @params = $methods[0]->params->names;
+
+is($#params,0);
+
+is ($methods[0]->params->get($params[0]), 'stalled');
_______________________________________________
Rt-commit mailing list
Rt-commit@lists.bestpractical.com
http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-commit