annotate lib/Benzin/Bugzilla/XmlWriter.pm @ 11:4eb9fdf4efa9

refactoring, non-working bookings
author cin
date Mon, 07 Sep 2015 19:18:21 +0300
parents 14a966369278
children 52b34ea50eff
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 = (
11
4eb9fdf4efa9 refactoring, non-working bookings
cin
parents: 10
diff changeset
4 'Benzin::Bugzilla::Bug' => 'WriteBug',
10
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
5 'Benzin::Bugzilla::BugComment' => 'WriteBugComment',
11
4eb9fdf4efa9 refactoring, non-working bookings
cin
parents: 10
diff changeset
6 'HASH' => 'WriteHash',
4eb9fdf4efa9 refactoring, non-working bookings
cin
parents: 10
diff changeset
7 'DateTime' => 'WriteTJ3DateTime',
4eb9fdf4efa9 refactoring, non-working bookings
cin
parents: 10
diff changeset
8 -plain => 'WriteValue',
4eb9fdf4efa9 refactoring, non-working bookings
cin
parents: 10
diff changeset
9 -default => 'WriteValue'
10
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
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
12 use IMPL::Const qw(:prop);
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
13 use IMPL::declare {
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
14 require => {
11
4eb9fdf4efa9 refactoring, non-working bookings
cin
parents: 10
diff changeset
15 XMLWriter => 'XML::Writer',
4eb9fdf4efa9 refactoring, non-working bookings
cin
parents: 10
diff changeset
16 Bug => 'Benzin::Bugzilla::Bug',
4eb9fdf4efa9 refactoring, non-working bookings
cin
parents: 10
diff changeset
17 BugComment => 'Benzin::Bugzilla::BugComment',
10
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
18 },
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
19 base => [
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
20 'IMPL::Transform' => sub { %Transform }
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
21 ],
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
22 props => [
11
4eb9fdf4efa9 refactoring, non-working bookings
cin
parents: 10
diff changeset
23 _writer => PROP_RW,
4eb9fdf4efa9 refactoring, non-working bookings
cin
parents: 10
diff changeset
24 timereports => PROP_RW,
4eb9fdf4efa9 refactoring, non-working bookings
cin
parents: 10
diff changeset
25 timeresolution => PROP_RW
10
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
26 ]
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
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
29 use fields qw(_writer);
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 sub CTOR {
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
32 my SELF $this = shift;
11
4eb9fdf4efa9 refactoring, non-working bookings
cin
parents: 10
diff changeset
33
4eb9fdf4efa9 refactoring, non-working bookings
cin
parents: 10
diff changeset
34 $this->_writer( XMLWriter->new(@_) );
10
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
35 }
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
36
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
37 sub WriteBugList {
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
38 my SELF $this = shift;
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
39 my $bugs = shift || [];
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
40 my $writer = $this->_writer;
11
4eb9fdf4efa9 refactoring, non-working bookings
cin
parents: 10
diff changeset
41
10
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
42 $writer->xmlDecl("UTF-8");
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
43 $writer->startTag("bugzilla");
11
4eb9fdf4efa9 refactoring, non-working bookings
cin
parents: 10
diff changeset
44
10
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
45 foreach my $bug (@$bugs) {
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
46 $writer->startTag("bug");
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
47 $this->WriteBug($bug);
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
48 $writer->endTag();
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
49 }
11
4eb9fdf4efa9 refactoring, non-working bookings
cin
parents: 10
diff changeset
50
10
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
51 $writer->endTag();
11
4eb9fdf4efa9 refactoring, non-working bookings
cin
parents: 10
diff changeset
52
10
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
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
55 sub WriteBug {
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
56 my SELF $this = shift;
11
4eb9fdf4efa9 refactoring, non-working bookings
cin
parents: 10
diff changeset
57 my $value = shift;
10
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
58 my $writer = $this->_writer;
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
59
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
60 foreach my $field ( @{ Bug->BUG_FIELDS } ) {
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
61 next unless $value->{$field};
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
62 $this->WriteElement( $field, $value->{$field} );
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
63 }
11
4eb9fdf4efa9 refactoring, non-working bookings
cin
parents: 10
diff changeset
64 $this->WriteElement( 'time',
4eb9fdf4efa9 refactoring, non-working bookings
cin
parents: 10
diff changeset
65 $value->GetTimeReports( $this->timeresolution ) )
4eb9fdf4efa9 refactoring, non-working bookings
cin
parents: 10
diff changeset
66 if $this->timereports;
10
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
67 }
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
68
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
69 sub WriteBugComment {
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
70 my SELF $this = shift;
11
4eb9fdf4efa9 refactoring, non-working bookings
cin
parents: 10
diff changeset
71 my $value = shift;
10
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
72 my $writer = $this->_writer;
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 foreach my $field ( @{ BugComment->COMMENT_FIELDS } ) {
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
75 next unless $value->{$field};
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
76 $this->WriteElement( $field, $value->{$field} );
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
77 }
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
78 }
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 sub WriteHash {
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
81 my SELF $this = shift;
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
82 my $value = shift;
11
4eb9fdf4efa9 refactoring, non-working bookings
cin
parents: 10
diff changeset
83
4eb9fdf4efa9 refactoring, non-working bookings
cin
parents: 10
diff changeset
84 while ( my ( $k, $v ) = each %$value ) {
4eb9fdf4efa9 refactoring, non-working bookings
cin
parents: 10
diff changeset
85 $this->WriteElement( $k, $v );
10
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
86 }
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
87 }
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
88
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
89 sub WriteElement {
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
90 my SELF $this = shift;
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
91 my ( $name, $data ) = @_;
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
92 my $writer = $this->_writer;
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
93
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
94 my @values =
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
95 ref($data)
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
96 && ref($data) eq 'ARRAY'
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
97 ? @{$data}
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
98 : $data;
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
99
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
100 foreach my $v (@values) {
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
101 $writer->startTag($name);
11
4eb9fdf4efa9 refactoring, non-working bookings
cin
parents: 10
diff changeset
102 $this->Transform($v);
10
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
103 $writer->endTag;
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
104 }
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
105 }
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 sub WriteValue {
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
108 my SELF $this = shift;
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
109 my $value = shift;
11
4eb9fdf4efa9 refactoring, non-working bookings
cin
parents: 10
diff changeset
110
10
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
111 $this->_writer->characters($value) if defined $value;
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
112 }
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
113
11
4eb9fdf4efa9 refactoring, non-working bookings
cin
parents: 10
diff changeset
114 sub WriteTJ3DateTime {
4eb9fdf4efa9 refactoring, non-working bookings
cin
parents: 10
diff changeset
115 my SELF $this = shift;
4eb9fdf4efa9 refactoring, non-working bookings
cin
parents: 10
diff changeset
116 my $value = shift;
4eb9fdf4efa9 refactoring, non-working bookings
cin
parents: 10
diff changeset
117
4eb9fdf4efa9 refactoring, non-working bookings
cin
parents: 10
diff changeset
118 $this->_writer->characters($value->strftime('%F-%T')) if defined $value;
4eb9fdf4efa9 refactoring, non-working bookings
cin
parents: 10
diff changeset
119 }
4eb9fdf4efa9 refactoring, non-working bookings
cin
parents: 10
diff changeset
120
10
14a966369278 working version of exporting bugs from bugzilla in tj3 format (without bookings)
cin
parents:
diff changeset
121 1;