line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MsOffice::Word::Surgeon::Revision; |
2
|
1
|
|
|
1
|
|
15
|
use 5.24.0; |
|
1
|
|
|
|
|
3
|
|
3
|
1
|
|
|
1
|
|
6
|
use Moose; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
4
|
1
|
|
|
1
|
|
7233
|
use MooseX::StrictConstructor; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
11
|
|
5
|
1
|
|
|
1
|
|
3236
|
use Moose::Util::TypeConstraints; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
12
|
|
6
|
1
|
|
|
1
|
|
2409
|
use Carp qw(croak); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
66
|
|
7
|
1
|
|
|
1
|
|
7
|
use POSIX qw(strftime); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9
|
|
8
|
1
|
|
|
1
|
|
2091
|
use MsOffice::Word::Surgeon::Utils qw(maybe_preserve_spaces); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
71
|
|
9
|
1
|
|
|
1
|
|
9
|
use namespace::clean -except => 'meta'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
14
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '2.03'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
subtype 'Date_ISO', |
14
|
|
|
|
|
|
|
as 'Str', |
15
|
|
|
|
|
|
|
where {/\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2})?Z?/}, |
16
|
|
|
|
|
|
|
message {"$_ is not a date in ISO format yyyy-mm-ddThh:mm:ss"}; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
#====================================================================== |
19
|
|
|
|
|
|
|
# ATTRIBUTES |
20
|
|
|
|
|
|
|
#====================================================================== |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has 'rev_id' => (is => 'ro', isa => 'Num', required => 1); |
23
|
|
|
|
|
|
|
has 'to_delete' => (is => 'ro', isa => 'Str'); |
24
|
|
|
|
|
|
|
has 'to_insert' => (is => 'ro', isa => 'Str'); |
25
|
|
|
|
|
|
|
has 'author' => (is => 'ro', isa => 'Str', default => 'Word::Surgeon'); |
26
|
|
|
|
|
|
|
has 'date' => (is => 'ro', isa => 'Date_ISO', default => |
27
|
|
|
|
|
|
|
sub {strftime "%Y-%m-%dT%H:%M:%SZ", localtime}); |
28
|
|
|
|
|
|
|
has 'run' => (is => 'ro', isa => 'MsOffice::Word::Surgeon::Run'); |
29
|
|
|
|
|
|
|
has 'xml_before' => (is => 'ro', isa => 'Str'); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
#====================================================================== |
33
|
|
|
|
|
|
|
# INSTANCE CONSTRUCTION |
34
|
|
|
|
|
|
|
#====================================================================== |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub BUILD { |
37
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
38
|
|
|
|
|
|
|
|
39
|
0
|
0
|
0
|
|
|
|
$self->to_delete || $self->to_insert |
40
|
|
|
|
|
|
|
or croak "attempt to create a Revision object without 'to_delete' nor 'to_insert' args"; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
#====================================================================== |
45
|
|
|
|
|
|
|
# METHODS |
46
|
|
|
|
|
|
|
#====================================================================== |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub as_xml { |
49
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
my $rev_id = $self->rev_id; |
52
|
0
|
|
|
|
|
|
my $date = $self->date; |
53
|
0
|
|
|
|
|
|
my $author = $self->author; |
54
|
0
|
0
|
0
|
|
|
|
my $props = $self->run && $self->run->props |
55
|
|
|
|
|
|
|
? "<w:rPr>" . $self->run->props . "</w:rPr>" |
56
|
|
|
|
|
|
|
: ""; |
57
|
0
|
|
|
|
|
|
my $xml = ""; |
58
|
|
|
|
|
|
|
|
59
|
0
|
0
|
|
|
|
|
if (my $to_delete = $self->to_delete) { |
60
|
0
|
|
|
|
|
|
my $space_attr = maybe_preserve_spaces($to_delete); |
61
|
0
|
|
|
|
|
|
$xml .= qq{<w:del w:id="$rev_id" w:author="$author" w:date="$date">} |
62
|
|
|
|
|
|
|
. qq{<w:r>$props} |
63
|
|
|
|
|
|
|
. qq{<w:delText$space_attr>$to_delete</w:delText>} |
64
|
|
|
|
|
|
|
. qq{</w:r>} |
65
|
|
|
|
|
|
|
. qq{</w:del>}; |
66
|
|
|
|
|
|
|
} |
67
|
0
|
0
|
|
|
|
|
if (my $to_insert = $self->to_insert) { |
68
|
0
|
|
|
|
|
|
my $space_attr = maybe_preserve_spaces($to_insert); |
69
|
0
|
|
0
|
|
|
|
$xml .= qq{<w:ins w:id="$rev_id" w:author="$author" w:date="$date">} |
70
|
|
|
|
|
|
|
. qq{<w:r>$props} |
71
|
|
|
|
|
|
|
. ($self->xml_before // '') |
72
|
|
|
|
|
|
|
. qq{<w:t$space_attr>$to_insert</w:t>} |
73
|
|
|
|
|
|
|
. qq{</w:r>} |
74
|
|
|
|
|
|
|
. qq{</w:ins>}; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
return $xml; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
1; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
__END__ |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=encoding ISO-8859-1 |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 NAME |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
MsOffice::Word::Surgeon::Revision - generate XML markup for MsWord revisions |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 DESCRIPTION |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
This class implements the XML markup generation algorithm |
93
|
|
|
|
|
|
|
for the method L<MsOffice::Word::Surgeon/new_revision>. |
94
|
|
|
|
|
|
|
See that method for a description of the API. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 INTERNALS |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
The constructor requires an integer C<rev_id> argument. |
99
|
|
|
|
|
|
|
The C<rev_id> is fed by the surgeon object which generates a fresh value at each call. |
100
|
|
|
|
|
|
|
This is inserted as C<w:id> attribute to the |
101
|
|
|
|
|
|
|
C<< <w:del> >> and C<< <w:ins> >> nodes -- but I don't really know why, |
102
|
|
|
|
|
|
|
since it doesn't seem to be used for any purpose by MsWord. |
103
|
|
|
|
|
|
|
|