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