minor fixes
[sgn.git] / lib / CXGN / List / Transform.pm
blob744fb547a122abb58eb0a39b4802990964e21ebb
2 =head1 NAME
4 CXGN::List::Transform - transform lists from one type to another
6 =head1 SYNOPSYS
8 my $tf = CXGN::List::Transform->new();
9 if (my $transform_name = $tf->can_transform("accessions", "accession_ids")) {
10 my $tf_list = @$tf->tranform($schema, $transform_name, $list_ref);
13 =cut
15 package CXGN::List::Transform;
17 use Moose;
19 use Module::Pluggable require => 1;
21 =head2 can_transform
23 Usage: my $tf_name = $tf->can_transform("accessions", "accession_ids");
24 Desc: ask if to types can be transformed. Returns the name of the
25 transform, to be used with the transform() function
26 Ret:
27 Args:
28 Side Effects:
29 Example:
31 =cut
33 sub can_transform {
34 my $self = shift;
35 my $type1 = shift;
36 my $type2 = shift;
38 foreach my $p ($self->plugins()) {
39 if ($p->can_transform($type1, $type2)) {
40 return $p->name();
43 return 0;
46 =head2 transform
48 Usage: $tf->transform($schema, $transform_name, $list_ref);
49 Desc:
50 Args: $schema (Bio::Chado::Schema)
51 $transform_name (obtain from can_transform())
52 $list_ref of elements to transform
53 Returns: a hashref with two keys, transform and missing, both
54 of which are arrayrefs of strings.
55 Side Effects:
56 Example:
58 =cut
60 sub transform {
61 my $self = shift;
62 my $schema = shift;
63 my $transform_name = shift;
64 my $list = shift;
66 my $data;
68 foreach my $p ($self->plugins()) {
69 if ($transform_name eq $p->name()) {
70 $data = $p->transform($schema, $list);
73 return $data;