[Rt-commit] [svn] r1504 - in experiments/Bamboo: . lib/Bamboo/Model
lib/Bamboo/Model/ProxyObject/RT
jesse at pallas.eruditorum.org
jesse at pallas.eruditorum.org
Sat Sep 18 17:45:38 EDT 2004
Author: jesse
Date: Sat Sep 18 17:45:37 2004
New Revision: 1504
Modified:
experiments/Bamboo/ (props changed)
experiments/Bamboo/lib/Bamboo/Model/ProxyObject.pm
experiments/Bamboo/lib/Bamboo/Model/ProxyObject/RT/Queue.pm
Log:
r10292 at tinbook: jesse | 2004-09-18T20:48:39.968423Z
Proxy object code was renamed to be nice, regular lower case.
Proxy object instantiation was cleaned up.
Methods were documented.
New method stubs were added.
A good time was had by all.
Modified: experiments/Bamboo/lib/Bamboo/Model/ProxyObject.pm
==============================================================================
--- experiments/Bamboo/lib/Bamboo/Model/ProxyObject.pm (original)
+++ experiments/Bamboo/lib/Bamboo/Model/ProxyObject.pm Sat Sep 18 17:45:37 2004
@@ -8,6 +8,8 @@
use vars qw($_RENDER $_METHODS $_ERRORS );
+# testing {{{
+
=begin testing
@@ -19,36 +21,25 @@
use_ok(Bamboo::Model::ProxyObject);
my $blank = Bamboo::Model::ProxyObject->new();
-ok( !$blank, $blank );
+isnt( !$blank, $blank );
use_ok(RT::Queue);
use_ok(RT::CurrentUser);
-my $rtqueue = 'RT::Queue';
-my $foo = Bamboo::Model::ProxyObject->new(
- Type => $rtqueue,
- id => '1'
-);
+my $root = RT::CurrentUser->new('root');
+ok($root->id, "got a root user");
-is($foo, undef, $foo );
-$foo = Bamboo::Model::ProxyObject->new(
- CurrentUser => RT::CurrentUser->new('root'),
- id => '1'
+my $rtqueue = 'RT::Queue';
+my $foo = Bamboo::Model::ProxyObject->new(
+ type => $rtqueue,
);
-is($foo, undef, $foo );
-
-$foo = Bamboo::Model::ProxyObject->new(
- Type => $rtqueue,
- CurrentUser => RT::CurrentUser->new('root'),
-);
-is($foo, undef, $foo );
+is($foo, undef);
$foo = Bamboo::Model::ProxyObject->new(
- Type => $rtqueue,
- CurrentUser => RT::CurrentUser->new('root'),
- id => '1'
+ type => $rtqueue,
+ current_user => $root,
);
-ok( $foo, "Type is $rtqueue, Currentuser is root and id is 1 - '$foo'" );
+ok( $foo, "type is $rtqueue, current_user is root and id is 1 - '$foo'" );
is( ref($foo), 'Bamboo::Model::ProxyObject::RT::Queue' );
=end testing
@@ -56,18 +47,21 @@
=cut
+# }}} testing
+
+# new {{{
=head2 new PARAMHASH
Create a new proxy object for some object type that Bamboo knows about.
=over
-=item Type
+=item type
The type of the _original_ object, not the Bamboo:: proxy for it.
-=item CurrentUser
+=item current_user
=item id
@@ -78,49 +72,67 @@
=cut
sub new {
+ my $proto = shift;
my %args;
- my $self = {};
- eval {
+ eval {
%args = validate(
@_,
{
- Type => { type => SCALAR },
- CurrentUser => { isa => 'RT::CurrentUser' },
- id => { regex => qr/^\d+$/ }
+ type => { type => SCALAR },
+ current_user => { isa => 'RT::CurrentUser' },
}
);
};
-
if ($@) {
- #RecordNote(undef, Message => $@);
+
+ _record_note(undef, message => $@);
return (undef);
}
-
warn "XXX: We need to validate against a typemap of safe objects";
- my $object_type = "Bamboo::Model::ProxyObject::" . $args{'Type'};
- print "OBject type is $object_type";
- eval "require $object_type";
+ my $class = "Bamboo::Model::ProxyObject::" . $args{'type'};
+
+ eval "require $class";
if ($@) {
- return("-1");
+ return("-1");
}
- bless( $self, $object_type );
+
+ my $self = {};
+ bless( $self, $class );
return ($self);
}
-sub ProxyForObject {
+# }}}
+
+sub proxy_for_object {
my $self = shift;
if ( $_[0] ) {
my $object = shift;
- $self->{_Object} = $object;
+ $self->{_object} = $object;
}
- return ( $self->{_Object} );
+ return ( $self->{_object} );
}
-sub HasMethod { # should this be called 'can'
+# has_method {{{
+
+=head2 has_method method
+
+Does this proxy object have a given method
+
+=over
+
+=item methodNAME
+
+Name of the method we're looking for
+
+=back
+
+=cut
+
+sub has_method { # should this be called 'can'
my $self = shift;
my $method = shift;
@@ -133,33 +145,42 @@
}
-=head2 MethodParameters METHOD
+# }}}
-Takes a scalar name of a method
-Returns a reference to a hash whose keys are the parameters this method takes.
-The value of each hash parameter points to a canonicalizer and validator for that parameter.
+# method_arguments {{{
+=head2 method_arguments method
+
+Takes a scalar name of a method.
+Returns a reference to a hash whose keys are the arguments this method takes.
+The value of each hash argument is a reference to a canonicalizer and validator for that argument.
+
+XXX TODO: should return a Bamboo::Model::arguments object
=cut
-sub MethodParameters {
+sub method_arguments {
my $self = shift;
my $method = shift;
- #return the parameters this object expects for this method
+ #return the arguments this object expects for this method
return ( $_METHODS->{$method}->{params} );
}
-sub MethodHasParameter {
+# }}}
+
+# method_has_argument {{{
+
+sub method_has_argument {
my $self = shift;
my %args = (
- Method => undef,
- Parameter => undef,
+ method => undef,
+ argument => undef,
@_
);
- if ( $self->MethodParameter( $args{'Method'} )->{ $args{'Parameter'} } ) {
+ if ( $self->method_argument( $args{'method'} )->{ $args{'argument'} } ) {
return (1);
}
else {
@@ -168,98 +189,91 @@
}
-sub RendererForAttribute {
- my $self = shift;
- my %args = (
- Attribute => undef,
- Mode => 'Display',
- @_
- );
-
- my $renderer = $_RENDER->{ $args{'Attribute'} }->{ $args{'Mode'} };
- if ( ref($renderer) ) {
-
-# if we get a reference, we have something more than a simple component renderer
-# for example, RT::Ticket->Requestors should by default render as an unordered list of the Members of the requestors group
-
- }
+# }}}
- return ($renderer);
-}
+# validate_method_call {{{
-=head2 ValidateMethodCall { Method => SCALAR, Parameters => HASHREF }
+=head2 validate_method_call { method => SCALAR, arguments => HASHREF }
-Takes a method name and a hashref to the proposed parameters for this method.
-Validates the method and proposed parameters. Returns true if the method call is safe to make and false if not.
+Takes a method name and a hashref to the proposed arguments for this method.
+Validates the method and proposed arguments. Returns true if the method call is safe to make and false if not.
-** This method canonicalizes and massages the parameters in place.
+** This method canonicalizes and massages the arguments in place.
=cut
-sub ValidateMethodCall {
+sub validate_method_call {
my $self = shift;
my %args = (
- Method => undef,
- Parameters => undef,
+ method => undef,
+ arguments => undef,
@_
);
# make sure it's an ok method
- return undef unless ( $self->HasMethod( $args{'Method'} ) );
+ return undef unless ( $self->has_method( $args{'method'} ) );
- # canonicalize each parameter
- $self->CanonicalizeMethodParameters(
- Parameters => $args{'Parameters'},
- Method => $args{'Method'}
+ # make sure only known arguments are listed
+ $self->prune_method_arguments(
+ arguments => $args{'arguments'},
+ method => $args{'method'}
);
- # make sure only known parameters are listed
- $self->PruneMethodParameters(
- Parameters => $args{'Parameters'},
- Method => $args{'Method'}
+ # canonicalize each argument
+ $self->canonicalize_method_arguments(
+ arguments => $args{'arguments'},
+ method => $args{'method'}
);
- # make sure that each of the parameters is valid
+ # make sure that each of the arguments is valid
#XX Call the validate sub
}
-sub PruneMethodParameters {
- my $self = shift;
- my %args = (
- Parameters => undef,
- Method => undef,
- @_
- );
+# }}}
-}
+# {{{ prune_method_arguments
-sub CanonicalizeMethodParameters {
+=head2 prune_method_arguments
+
+Remove arguments that aren't valid arguments for this method
+
+=over
+
+=item method
+
+=item arguments
+
+=back
+
+=cut
+
+sub prune_method_arguments {
my $self = shift;
my %args = (
- Parameters => undef,
- Method => undef,
+ arguments => undef,
+ method => undef,
@_
);
- foreach my $param ( keys %{ $args{'Parameters'} } ) {
+ foreach my $param ( keys %{ $args{'arguments'} } ) {
unless (
- $self->MethodHasParameter(
- Method => $args{'Method'},
- Parameter => $param
+ $self->method_has_argument(
+ method => $args{'method'},
+ argument => $param
)
)
{
- $self->RecordNote( Object => $self,
- Method => $args{'Method'},
- Parameter => $param,
- Message => 'No such parameter');
- delete $args{'Parameters'}->{$param};
+ $self->_record_note( object => $self,
+ method => $args{'method'},
+ argument => $param,
+ message => 'No such argument');
+ delete $args{'arguments'}->{$param};
}
}
@@ -267,21 +281,81 @@
}
-sub RecordNote {
+# }}}
+
+# canonicalize_method_arguments {{{
+
+
+=head2 canonicalize_method_arguments
+
+Remove arguments that aren't valid arguments for this method
+
+=over
+
+=item method
+
+=item arguments
+
+=back
+
+=cut
+
+sub canonicalize_method_arguments {
my $self = shift;
- my %args = ( Object => 'No object',
- Method => 'unknown',
- Parameter => undef,
- Severity => undef,
- Value => undef,
- Message => undef,
+ my %args = (
+ arguments => undef,
+ method => undef,
+ @_
+ );
+
+ foreach my $param ( keys %{ $args{'arguments'} } ) {
+ warn "Not canonicalizing yet";
+ }
+
+}
+
+# }}}
+
+sub _record_note {
+ my $self = shift;
+ my %args = ( object => 'No object',
+ method => 'unknown',
+ argument => undef,
+ severity => undef,
+ value => undef,
+ message => undef,
@_
);
- push @{$_NOTES{$args{'Object'}}{$args{'Method'}}}, \%args;
+ push @{$_NOTES{$args{'object'}}{$args{'method'}}}, \%args;
}
+=head1 What it needs to do
+
+=head2 new
+
+Create a proxy object
+
+
+=head2 load_proxied_object
+
+Load the object behind the proxy object
+
+=head2 call_method
+
+Perform method calls on the object behind the proxy object.
+
+=head2 methods
+
+Find out what methods the proxy object supports.
+
+=head2 method_info
+
+For a given method that the proxy object supports, find out what its params are and what their types/validations are
+
+=cut
+
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 Sat Sep 18 17:45:37 2004
@@ -1,9 +1,12 @@
use strict;
-package RT::Web::ProxyObject::RT::Queue;
+package Bamboo::Model::ProxyObject::RT::Queue;
+
+use base qw/Bamboo::Model::ProxyObject/;
+
+
-use base qw/RT::Web::ProxyObject/;
=begin block
More information about the Rt-commit
mailing list