aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Reaction/InterfaceModel/Reflector/SearchSpec.pm
diff options
context:
space:
mode:
authorphaylon <phaylon@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7>2009-03-27 02:40:02 +0000
committerphaylon <phaylon@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7>2009-03-27 02:40:02 +0000
commite653a48785a1942da650254c8fba30706ca18333 (patch)
treee0478436bd4a61b1d34af9cf1e770e7e02dba99f /lib/Reaction/InterfaceModel/Reflector/SearchSpec.pm
parent0feb9d76b60db643a717dded5c19efb8f049f642 (diff)
downloadreaction-e653a48785a1942da650254c8fba30706ca18333.tar.gz
reaction-e653a48785a1942da650254c8fba30706ca18333.zip
search spec components factored out of T365
Diffstat (limited to 'lib/Reaction/InterfaceModel/Reflector/SearchSpec.pm')
-rw-r--r--lib/Reaction/InterfaceModel/Reflector/SearchSpec.pm53
1 files changed, 53 insertions, 0 deletions
diff --git a/lib/Reaction/InterfaceModel/Reflector/SearchSpec.pm b/lib/Reaction/InterfaceModel/Reflector/SearchSpec.pm
new file mode 100644
index 0000000..9d8b905
--- /dev/null
+++ b/lib/Reaction/InterfaceModel/Reflector/SearchSpec.pm
@@ -0,0 +1,53 @@
+package Reaction::InterfaceModel::Reflector::SearchSpec;
+
+use Moose::Exporter;
+use Carp qw(confess);
+use Reaction::Types::Core qw(SimpleStr NonEmptySimpleStr);
+#use aliased 'T365::BrokerInterface::SearchSpec';
+use aliased 'Moose::Meta::TypeConstraint::Enum';
+
+sub reflect_attributes_from_target {
+ my ($caller, $foreign) = @_;
+ confess 'Class name to reflect search specification is required as first argument to reflect_attributes_from_target'
+ unless $foreign;
+# $foreign ||= SearchSpec;
+ my $meta = Class::MOP::Class->initialize($caller);
+ my %info;
+ foreach my $attr (
+ grep { $_->name !~ /^_/ }
+ $foreign->meta->get_all_attributes
+ ) {
+#warn "Doing ".$attr->name;
+ my %args;
+ { my @copy = qw(required is isa);
+ @args{@copy} = @{$attr}{@copy};
+ }
+ if ($args{isa} eq NonEmptySimpleStr) {
+#warn "here ".$attr->name." ".join(', ', %args);
+ if ($args{required}) {
+ confess "I really have no idea how we got here";
+ } else {
+ $args{isa} = SimpleStr;
+ $args{required} = 1;
+ push(@{$info{empty}||=[]}, $attr->name);
+ }
+ } else {
+ push(@{$info{normal}||=[]}, $attr->name);
+#warn "here instead ".$attr->name;
+ }
+ my $tc;
+ if (($tc = $args{type_constraint}) && ($tc->isa(Enum))) {
+ $args{valid_values} = $tc->values;
+ }
+ $args{predicate} = "has_".$attr->name;
+ $meta->add_attribute($attr->name => \%args);
+ }
+ \%info;
+}
+
+Moose::Exporter->setup_import_methods(
+ with_caller => [ 'reflect_attributes_from_target' ]
+);
+
+1;
+