| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package XML::Loy::ActivityStreams; |
|
2
|
4
|
|
|
4
|
|
3842
|
use strict; |
|
|
4
|
|
|
|
|
11
|
|
|
|
4
|
|
|
|
|
127
|
|
|
3
|
4
|
|
|
4
|
|
23
|
use warnings; |
|
|
4
|
|
|
|
|
7
|
|
|
|
4
|
|
|
|
|
140
|
|
|
4
|
4
|
|
|
|
|
23
|
use XML::Loy with => ( |
|
5
|
|
|
|
|
|
|
prefix => 'activity', |
|
6
|
|
|
|
|
|
|
namespace => 'http://activitystrea.ms/schema/1.0/' |
|
7
|
4
|
|
|
4
|
|
21
|
); |
|
|
4
|
|
|
|
|
7
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# Todo: support to_json |
|
10
|
|
|
|
|
|
|
# Todo: verbs and object-types may need namespaces |
|
11
|
|
|
|
|
|
|
# Todo: Support ActivityStreams 2 as a anamespace |
|
12
|
|
|
|
|
|
|
|
|
13
|
4
|
|
|
4
|
|
29
|
use Carp qw/carp/; |
|
|
4
|
|
|
|
|
7
|
|
|
|
4
|
|
|
|
|
4100
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# No constructor |
|
16
|
|
|
|
|
|
|
sub new { |
|
17
|
1
|
|
|
1
|
1
|
536
|
carp 'Only use ' . __PACKAGE__ . ' as an extension to Atom'; |
|
18
|
1
|
|
|
|
|
584
|
return; |
|
19
|
|
|
|
|
|
|
}; |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# Add or get ActivityStreams actor |
|
22
|
|
|
|
|
|
|
sub actor { |
|
23
|
9
|
|
|
9
|
1
|
29
|
my $self = shift; |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# Set actor |
|
26
|
9
|
100
|
|
|
|
27
|
if ($_[0]) { |
|
27
|
5
|
|
|
|
|
23
|
my $actor = $self->author( @_ ); |
|
28
|
|
|
|
|
|
|
|
|
29
|
5
|
|
|
|
|
20
|
$actor->set('object-type', _check_prefix('person')); |
|
30
|
5
|
|
|
|
|
27
|
return $actor; |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# Get actor |
|
34
|
|
|
|
|
|
|
else { |
|
35
|
4
|
|
|
|
|
19
|
my $actor = $self->author->[0]; |
|
36
|
4
|
50
|
|
|
|
33
|
if ($actor) { |
|
37
|
|
|
|
|
|
|
|
|
38
|
4
|
|
|
|
|
30
|
my $object_type = $actor->children('object-type'); |
|
39
|
|
|
|
|
|
|
|
|
40
|
4
|
50
|
|
|
|
32
|
return unless $object_type = $object_type->[0]; |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# Prepend namespace if not defined |
|
43
|
4
|
50
|
|
|
|
38
|
if (index($object_type->text, '/') == -1) { |
|
44
|
0
|
|
|
|
|
0
|
$object_type->content( |
|
45
|
|
|
|
|
|
|
__PACKAGE__->_namespace . lc $object_type->text |
|
46
|
|
|
|
|
|
|
); |
|
47
|
|
|
|
|
|
|
}; |
|
48
|
|
|
|
|
|
|
|
|
49
|
4
|
|
|
|
|
162
|
return $actor; |
|
50
|
|
|
|
|
|
|
}; |
|
51
|
|
|
|
|
|
|
}; |
|
52
|
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
0
|
return; |
|
54
|
|
|
|
|
|
|
}; |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# Add or get ActivityStreams verb |
|
58
|
|
|
|
|
|
|
sub verb { |
|
59
|
10
|
|
|
10
|
1
|
17
|
my $self = shift; |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# Set verb |
|
62
|
10
|
100
|
|
|
|
27
|
if ($_[0]) { |
|
63
|
5
|
|
|
|
|
14
|
return $self->set(verb => _check_prefix($_[0])); |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# Get verb |
|
67
|
|
|
|
|
|
|
else { |
|
68
|
5
|
|
|
|
|
19
|
my $verb = $self->children('verb'); |
|
69
|
|
|
|
|
|
|
|
|
70
|
5
|
50
|
|
|
|
44
|
return unless $verb = $verb->[0]; |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# Prepend namespace if not defined |
|
73
|
5
|
50
|
|
|
|
51
|
if (index($verb->text, '/') == -1) { |
|
74
|
0
|
|
|
|
|
0
|
my $nverb = __PACKAGE__->_namespace . lc $verb->text; |
|
75
|
0
|
|
|
|
|
0
|
$verb->content($nverb); |
|
76
|
0
|
|
|
|
|
0
|
return $nverb; |
|
77
|
|
|
|
|
|
|
}; |
|
78
|
|
|
|
|
|
|
|
|
79
|
5
|
|
|
|
|
164
|
return $verb->text; |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
}; |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# Add or get ActivityStreams object |
|
85
|
|
|
|
|
|
|
sub object { |
|
86
|
7
|
|
|
7
|
1
|
74
|
shift->_target_object(object => @_ ); |
|
87
|
|
|
|
|
|
|
}; |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# Add or get ActivityStreams target |
|
91
|
|
|
|
|
|
|
sub target { |
|
92
|
3
|
|
|
3
|
1
|
14
|
shift->_target_object(target => @_ ); |
|
93
|
|
|
|
|
|
|
}; |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub _target_object { |
|
97
|
10
|
|
|
10
|
|
19
|
my $self = shift; |
|
98
|
10
|
|
|
|
|
17
|
my $type = shift; |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# Add target or object |
|
101
|
10
|
100
|
|
|
|
25
|
if ($_[0]) { |
|
102
|
4
|
|
|
|
|
14
|
my %params = @_; |
|
103
|
|
|
|
|
|
|
|
|
104
|
4
|
|
|
|
|
13
|
my $obj = $self->set($type); |
|
105
|
|
|
|
|
|
|
|
|
106
|
4
|
50
|
|
|
|
16
|
$obj->id( delete $params{id} ) if exists $params{id}; |
|
107
|
|
|
|
|
|
|
|
|
108
|
4
|
100
|
|
|
|
16
|
if (exists $params{'object-type'}) { |
|
109
|
|
|
|
|
|
|
|
|
110
|
3
|
|
|
|
|
7
|
my $type = delete $params{'object-type'}; |
|
111
|
|
|
|
|
|
|
|
|
112
|
3
|
|
|
|
|
8
|
$obj->set('object-type', _check_prefix($type)); |
|
113
|
|
|
|
|
|
|
}; |
|
114
|
|
|
|
|
|
|
|
|
115
|
4
|
|
|
|
|
16
|
foreach (keys %params) { |
|
116
|
4
|
|
|
|
|
20
|
$obj->add('-' . $_ => $params{$_}); |
|
117
|
|
|
|
|
|
|
}; |
|
118
|
|
|
|
|
|
|
|
|
119
|
4
|
|
|
|
|
36
|
return $obj; |
|
120
|
|
|
|
|
|
|
} |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
# Get target or object |
|
123
|
|
|
|
|
|
|
else { |
|
124
|
6
|
|
|
|
|
22
|
my $obj = $self->at($type); |
|
125
|
|
|
|
|
|
|
|
|
126
|
6
|
50
|
|
|
|
117
|
return unless $obj->[0]; |
|
127
|
|
|
|
|
|
|
|
|
128
|
6
|
|
|
|
|
191
|
my $object_type = $obj->children('object-type')->[0]; |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
# Prepend namespace if not defined |
|
131
|
6
|
50
|
|
|
|
53
|
if (index($object_type->text, '/') == -1) { |
|
132
|
0
|
|
|
|
|
0
|
$object_type->content( |
|
133
|
|
|
|
|
|
|
__PACKAGE__->_namespace . lc($object_type->text) |
|
134
|
|
|
|
|
|
|
); |
|
135
|
|
|
|
|
|
|
}; |
|
136
|
|
|
|
|
|
|
|
|
137
|
6
|
|
|
|
|
222
|
return $obj; |
|
138
|
|
|
|
|
|
|
}; |
|
139
|
|
|
|
|
|
|
}; |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
# Prefix relative object types and verbs with |
|
143
|
|
|
|
|
|
|
# ActivityStreams namespace |
|
144
|
|
|
|
|
|
|
sub _check_prefix { |
|
145
|
13
|
100
|
|
13
|
|
54
|
if (index($_[0], '/') == -1) { |
|
146
|
10
|
|
|
|
|
33
|
return __PACKAGE__->_namespace . lc $_[0]; |
|
147
|
|
|
|
|
|
|
}; |
|
148
|
3
|
|
|
|
|
8
|
return $_[0]; |
|
149
|
|
|
|
|
|
|
}; |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
1; |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
__END__ |