annotate lib/Benzin/Bugzilla/XmlWriter.pm @ 10:14a966369278

working version of exporting bugs from bugzilla in tj3 format (without bookings)
author cin
date Mon, 07 Sep 2015 01:37:11 +0300
parents
children 4eb9fdf4efa9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
1 package Benzin::Bugzilla::XmlWriter;
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
2
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
3 our %Transform = (
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
4 'Benzin::Bugzilla::Bug' => 'WriteBug',
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
5 'Benzin::Bugzilla::BugComment' => 'WriteBugComment',
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
6 'HASH' => 'WriteHash',
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
7 -plain => 'WriteValue',
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
8 -default => 'WriteValue'
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
9 );
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
10
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
11 use IMPL::Const qw(:prop);
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
12 use IMPL::declare {
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
13 require => {
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
14 XMLWriter => 'XML::Writer',
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
15 Bug => 'Benzin::Bugzilla::Bug',
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
16 BugComment => 'Benzin::Bugzilla::BugComment'
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
17 },
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
18 base => [
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
19 'IMPL::Transform' => sub { %Transform }
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
20 ],
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
21 props => [
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
22 _writer => PROP_RW
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
23 ]
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
24 };
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
25
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
26 use fields qw(_writer);
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
27
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
28 sub CTOR {
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
29 my SELF $this = shift;
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
30
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
31 $this->_writer(XMLWriter->new(@_));
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
32 }
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
33
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
34 sub WriteBugList {
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
35 my SELF $this = shift;
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
36 my $bugs = shift || [];
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
37 my $writer = $this->_writer;
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
38
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
39
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
40 $writer->xmlDecl("UTF-8");
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
41 $writer->startTag("bugzilla");
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
42
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
43
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
44 foreach my $bug (@$bugs) {
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
45 $writer->startTag("bug");
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
46 $this->WriteBug($bug);
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
47 $writer->endTag();
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
48 }
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
49
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
50 $writer->endTag();
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
51
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
52 }
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
53
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
54 sub WriteBug {
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
55 my SELF $this = shift;
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
56 my $value = shift;
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
57 my $writer = $this->_writer;
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
58
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
59 foreach my $field ( @{ Bug->BUG_FIELDS } ) {
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
60 next unless $value->{$field};
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
61 $this->WriteElement( $field, $value->{$field} );
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
62 }
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
63 }
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
64
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
65 sub WriteBugComment {
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
66 my SELF $this = shift;
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
67 my $value = shift;
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
68 my $writer = $this->_writer;
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
69
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
70 foreach my $field ( @{ BugComment->COMMENT_FIELDS } ) {
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
71 next unless $value->{$field};
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
72 $this->WriteElement( $field, $value->{$field} );
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
73 }
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
74 }
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
75
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
76 sub WriteHash {
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
77 my SELF $this = shift;
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
78 my $value = shift;
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
79
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
80 while(my ($k,$v) = each %$value) {
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
81 $this->WriteElement($k,$v);
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
82 }
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
83 }
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
84
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
85 sub WriteElement {
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
86 my SELF $this = shift;
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
87 my ( $name, $data ) = @_;
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
88 my $writer = $this->_writer;
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
89
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
90 my @values =
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
91 ref($data)
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
92 && ref($data) eq 'ARRAY'
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
93 ? @{$data}
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
94 : $data;
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
95
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
96 foreach my $v (@values) {
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
97 $writer->startTag($name);
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
98 $this->Transform( $v );
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
99 $writer->endTag;
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
100 }
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
101 }
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
102
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
103 sub WriteValue {
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
104 my SELF $this = shift;
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
105 my $value = shift;
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
106
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
107 $this->_writer->characters($value) if defined $value;
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
108 }
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
109
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
110 1;