| 1 | # NOTE: This implementation is obviously incomplete. Don't try to use it. | ||
| 2 | |||
| 3 | package Boulder::Labbase; | ||
| 4 | |||
| 5 | # Given access to a boulderio schema for Labbase, return information | ||
| 6 | # about tokens (materials). | ||
| 7 | |||
| 8 | use Boulder::Stream; | ||
| 9 | |||
| 10 | require Exporter; | ||
| 11 | @ISA = qw(Exporter Boulder::Stream); | ||
| 12 | @EXPORT = (); | ||
| 13 | @EXPORT_OK = (); | ||
| 14 | |||
| 15 | use Carp; | ||
| 16 | use LabBase; | ||
| 17 | |||
| 18 | # To create a new Boulder::Stream use new(). | ||
| 19 | # new() takes named parameters: | ||
| 20 | # -schema=> A Stone() object containing the schema for the token. | ||
| 21 | # -in=> LabBase object to get tokens from. | ||
| 22 | # -out=> LabBase object to store tokens into. | ||
| 23 | # | ||
| 24 | |||
| 25 | # To fetch the Stone object corresponding to a token | ||
| 26 | # use get() -or- read_record(). | ||
| 27 | # The semantics of tag name lists are the same as in | ||
| 28 | # Boulder::Stream. | ||
| 29 | |||
| 30 | # To store the Stone object corresponding to a token: | ||
| 31 | # use put() -or- write_record(). | ||
| 32 | # parameters: | ||
| 33 | # -token=> token to write | ||
| 34 | # -step=> the current step | ||
| 35 | # -workflow=> the current workflow name | ||
| 36 | # -state=> name of the current state | ||
| 37 | |||
| 38 | sub new { | ||
| 39 | my($package) = shift; | ||
| 40 | my($schema,$in,$out) = rearrange([SCHEMA,IN,OUT],@_); | ||
| 41 | $out = $in unless $out; | ||
| 42 | croak "Usage: Boulder::Labbase::new(-schema=>schema,-in=>lb_in,-out=>lb_out)\n" | ||
| 43 | unless ref($schema)=~/Stone/ && ref($in)=~/LabBase/; | ||
| 44 | |||
| 45 | # superclass constructor | ||
| 46 | my($self) = new Boulder::Stream(); | ||
| 47 | |||
| 48 | # Add some extra parameters to the object | ||
| 49 | $self->{'schema'} = $schema; | ||
| 50 | $self->{'IN'} = $in; | ||
| 51 | $self->{'OUT'} = $out; | ||
| 52 | $self->{'passthru'} = undef; | ||
| 53 | } | ||
| 54 | |||
| 55 | # This is a low-level routine for "priming the pump" on a token. | ||
| 56 | # It sends a query to the database which will be used later to | ||
| 57 | # create the token stream. You must pass it all the LabBase materials | ||
| 58 | # that are | ||
| 59 | # | ||
| 60 | sub fetch_token { | ||
| 61 | my($self) = shift; | ||
| 62 | my($ | ||
| 63 | } | ||
| 64 | |||
| 65 | sub rearrange { | ||
| 66 | my($self,$order,@param) = @_; | ||
| 67 | return () unless @param; | ||
| 68 | |||
| 69 | return @param unless (defined($param[0]) && substr($param[0],0,1) eq '-') | ||
| 70 | || $self->use_named_parameters; | ||
| 71 | |||
| 72 | my $i; | ||
| 73 | for ($i=0;$i<@param;$i+=2) { | ||
| 74 | $param[$i]=~s/^\-//; # get rid of initial - if present | ||
| 75 | $param[$i]=~tr/a-z/A-Z/; # parameters are upper case | ||
| 76 | } | ||
| 77 | |||
| 78 | my(%param) = @param; # convert into associative array | ||
| 79 | my(@return_array); | ||
| 80 | |||
| 81 | my($key)=''; | ||
| 82 | foreach $key (@$order) { | ||
| 83 | my($value); | ||
| 84 | # this is an awful hack to fix spurious warnings when the | ||
| 85 | # -w switch is set. | ||
| 86 | if (ref($key) eq 'ARRAY') { | ||
| 87 | foreach (@$key) { | ||
| 88 | last if defined($value); | ||
| 89 | $value = $param{$_}; | ||
| 90 | delete $param{$_}; | ||
| 91 | } | ||
| 92 | } else { | ||
| 93 | $value = $param{$key}; | ||
| 94 | delete $param{$key}; | ||
| 95 | } | ||
| 96 | push(@return_array,$value); | ||
| 97 | } | ||
| 98 | push (@return_array,$self->make_attributes(\%param)) if %param; | ||
| 99 | return (@return_array); | ||
| 100 | } |