line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package XML::Loy::ActivityStreams; |
2
|
4
|
|
|
4
|
|
3363
|
use strict; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
103
|
|
3
|
4
|
|
|
4
|
|
18
|
use warnings; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
117
|
|
4
|
4
|
|
|
|
|
18
|
use XML::Loy with => ( |
5
|
|
|
|
|
|
|
prefix => 'activity', |
6
|
|
|
|
|
|
|
namespace => 'http://activitystrea.ms/schema/1.0/' |
7
|
4
|
|
|
4
|
|
20
|
); |
|
4
|
|
|
|
|
8
|
|
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
|
|
24
|
use Carp qw/carp/; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
3080
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# No constructor |
16
|
|
|
|
|
|
|
sub new { |
17
|
1
|
|
|
1
|
1
|
345
|
carp 'Only use ' . __PACKAGE__ . ' as an extension to Atom'; |
18
|
1
|
|
|
|
|
763
|
return; |
19
|
|
|
|
|
|
|
}; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# Add or get ActivityStreams actor |
22
|
|
|
|
|
|
|
sub actor { |
23
|
9
|
|
|
9
|
1
|
12
|
my $self = shift; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# Set actor |
26
|
9
|
100
|
|
|
|
20
|
if ($_[0]) { |
27
|
5
|
|
|
|
|
18
|
my $actor = $self->author( @_ ); |
28
|
|
|
|
|
|
|
|
29
|
5
|
|
|
|
|
14
|
$actor->set('object-type', _check_prefix('person')); |
30
|
5
|
|
|
|
|
19
|
return $actor; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# Get actor |
34
|
|
|
|
|
|
|
else { |
35
|
4
|
|
|
|
|
14
|
my $actor = $self->author->[0]; |
36
|
4
|
50
|
|
|
|
26
|
if ($actor) { |
37
|
|
|
|
|
|
|
|
38
|
4
|
|
|
|
|
22
|
my $object_type = $actor->children('object-type'); |
39
|
|
|
|
|
|
|
|
40
|
4
|
50
|
|
|
|
24
|
return unless $object_type = $object_type->[0]; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# Prepend namespace if not defined |
43
|
4
|
50
|
|
|
|
26
|
if (index($object_type->text, '/') == -1) { |
44
|
0
|
|
|
|
|
0
|
$object_type->content( |
45
|
|
|
|
|
|
|
__PACKAGE__->_namespace . lc $object_type->text |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
}; |
48
|
|
|
|
|
|
|
|
49
|
4
|
|
|
|
|
116
|
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
|
15
|
my $self = shift; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# Set verb |
62
|
10
|
100
|
|
|
|
20
|
if ($_[0]) { |
63
|
5
|
|
|
|
|
17
|
return $self->set(verb => _check_prefix($_[0])); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# Get verb |
67
|
|
|
|
|
|
|
else { |
68
|
5
|
|
|
|
|
14
|
my $verb = $self->children('verb'); |
69
|
|
|
|
|
|
|
|
70
|
5
|
50
|
|
|
|
37
|
return unless $verb = $verb->[0]; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# Prepend namespace if not defined |
73
|
5
|
50
|
|
|
|
35
|
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
|
|
|
|
|
143
|
return $verb->text; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
}; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# Add or get ActivityStreams object |
85
|
|
|
|
|
|
|
sub object { |
86
|
7
|
|
|
7
|
1
|
38
|
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
|
|
14
|
my $self = shift; |
98
|
10
|
|
|
|
|
15
|
my $type = shift; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# Add target or object |
101
|
10
|
100
|
|
|
|
32
|
if ($_[0]) { |
102
|
4
|
|
|
|
|
14
|
my %params = @_; |
103
|
|
|
|
|
|
|
|
104
|
4
|
|
|
|
|
12
|
my $obj = $self->set($type); |
105
|
|
|
|
|
|
|
|
106
|
4
|
50
|
|
|
|
15
|
$obj->id( delete $params{id} ) if exists $params{id}; |
107
|
|
|
|
|
|
|
|
108
|
4
|
100
|
|
|
|
10
|
if (exists $params{'object-type'}) { |
109
|
|
|
|
|
|
|
|
110
|
3
|
|
|
|
|
6
|
my $type = delete $params{'object-type'}; |
111
|
|
|
|
|
|
|
|
112
|
3
|
|
|
|
|
8
|
$obj->set('object-type', _check_prefix($type)); |
113
|
|
|
|
|
|
|
}; |
114
|
|
|
|
|
|
|
|
115
|
4
|
|
|
|
|
57
|
foreach (keys %params) { |
116
|
4
|
|
|
|
|
16
|
$obj->add('-' . $_ => $params{$_}); |
117
|
|
|
|
|
|
|
}; |
118
|
|
|
|
|
|
|
|
119
|
4
|
|
|
|
|
24
|
return $obj; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
# Get target or object |
123
|
|
|
|
|
|
|
else { |
124
|
6
|
|
|
|
|
18
|
my $obj = $self->at($type); |
125
|
|
|
|
|
|
|
|
126
|
6
|
50
|
|
|
|
93
|
return unless $obj->[0]; |
127
|
|
|
|
|
|
|
|
128
|
6
|
|
|
|
|
157
|
my $object_type = $obj->children('object-type')->[0]; |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
# Prepend namespace if not defined |
131
|
6
|
50
|
|
|
|
38
|
if (index($object_type->text, '/') == -1) { |
132
|
0
|
|
|
|
|
0
|
$object_type->content( |
133
|
|
|
|
|
|
|
__PACKAGE__->_namespace . lc($object_type->text) |
134
|
|
|
|
|
|
|
); |
135
|
|
|
|
|
|
|
}; |
136
|
|
|
|
|
|
|
|
137
|
6
|
|
|
|
|
172
|
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
|
|
40
|
if (index($_[0], '/') == -1) { |
146
|
10
|
|
|
|
|
24
|
return __PACKAGE__->_namespace . lc $_[0]; |
147
|
|
|
|
|
|
|
}; |
148
|
3
|
|
|
|
|
8
|
return $_[0]; |
149
|
|
|
|
|
|
|
}; |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
1; |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
__END__ |