Line # Revision Author
1 480 ahitrov <%once>
2
3 use JSON::XS;
4 my $json = JSON::XS->new;
5
6 </%once>
7 <%args>
8
9 $object => undef
10 $name => undef
11 $SETS => undef
12
13 </%args>
14 <%init>
15
16 return undef unless ref $SETS;
17 return undef unless $name;
18
19 return undef if $SETS->{$name} eq '';
20
21 warn "\nTAG Store:\n" if $DEBUG;
22 warn Dumper $SETS->{$name} if $DEBUG;
23
24 my ($prop) = grep { $_->{attr} eq $name } $object->structure;
25 return undef if exists $prop->{virtual} && $prop->{virtual};
26 my $class = $object->class;
27 my $is_extra = grep { ref $_ && $_->{attr} eq $name } $class->extra_properties ? 1 : 0;
28
29 my $result;
30 my @tags;
31 if ( $object->id ) {
32 @tags = $keeper->get_documents(
33 class => 'tag::Tag',
34 lclass => 'tag::Cloud',
35 ldest => $object->id,
36 ldestclass => $object->class,
37 );
38 if ( @tags ) {
39 $result = [];
40 foreach my $tag ( @tags ) {
41 push @$result, { id => $tag->id, name => Encode::decode('utf-8', $tag->name) };
42 }
43 }
44 unless ( $is_extra ) {
45 $result = Encode::encode('utf-8', $json->encode( $result ));
46 }
47 warn Dumper $result if $DEBUG;
48 return $result;
49 } else {
50 return undef;
51 }
52
53
54 </%init>