blib/lib/XML/gmcr.pl untested

filter: Statementstmt 0.0% 0 / 37 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 65 CC 1 SCAR 6.9
CC
1
Cov
0%
help
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 # /usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Getopt::Std;
7
8 my @events = qw(
9 On_Document_Save On_Document_SaveAs On_Before_Document_Save
10 On_Before_Document_SaveAs
11
12 On_Document_Open_Complete On_Document_Open_View On_Document_Close
13 On_Document_First_Draw
14
15 On_Update_UI
16
17 On_Update_ElementList On_ElementList_Insert On_ElementList_Change
18 On_ElementList_Surround On_ElementList_Insert_NoRequired
19
20 On_Application_Before_Document_Validate On_Before_Document_Validate
21 On_Application_Before_Selection_Validate On_Before_Selection_Validate
22 On_Application_After_Document_Validate On_After_Document_Validate
23 On_Application_After_Selection_Validate On_After_Selection_Validate
24 On_Check_Element_SimpleContent On_Check_Attribute_Value
25
26 On_Document_Activate On_Document_Deactivate
27
28 On_Before_Document_Preview
29
30 On_Click On_Double_Click
31
32 On_View_Change
33
34 On_Context_Menu
35
36 On_Document_Before_DropText On_Application_Document_Before_DropText
37 On_Document_After_DropText On_Application_Document_After_DropText
38
39 On_Drop_Files
40
41 On_Drop_URL On_Drag_Over_URL
42
43
44
45 On_Style_Element
46
47 );
48
49 my @file_events = qw(
50 File_Open File_Open_Template File_New File_Save File_SaveAs File_SaveAll
51 File_Close File_CloseAll File_Exit
52 );
53
54 my @mouse_events = qw(
55 On_Mouse_Over On_Mouse_Out
56 );
57
58 my @global_events = qw(
59 On_Application_Open On_Application_Close
60 On_Default_CommandBars_Complete
61 On_Application_Open_Complete
62 On_Application_Activate On_Application_Deactivate
63
64 On_DTD_Open_Complete
65
66 On_Application_Resolve_Entity_URL On_Application_Resolve_Image_URL
67  
68 );
69
70 our %opts;
71
72 getopts('mgh',\%opts);
73
74 #print map {"$_ => $opts{$_}\n"} keys %opts;
75
76 my $system_identifier;
77 my $perl_module;
78
79 {
80 &help if exists $opts{h};
81 push @events, @file_events if $opts{f};
82 push @events, @global_events if $opts{g};
83 push @events, @mouse_events if $opts{m};
84 $system_identifier = $ARGV[-2] || do {
85 warn "System identifier argument is missing\n";
86 &help;
87 };
88 $system_identifier =~ /\.dtd$/i || do {
89 warn "System identifier must end with .dtd or .DTD";
90 &help;
91 };
92 $perl_module = $ARGV[-1] || do {
93 warn "Module argument is missing\n";
94 &help;
95 };
96 }
97
98 print <<EOT
99 <?xml version="1.0"?>
100 <!DOCTYPE MACROS SYSTEM "macros.dtd">
101 <MACROS>
102 <MACRO name="On_Macro_File_Load" key="" lang="PerlScript">
103 <![CDATA[
104 use XML::XMetaL;
105 use $perl_module;
106
107 \$handler = $perl_module->new(-application => \$Application);
108
109 \$dispatcher = XML::XMetaL->new(-application => \$Application);
110 \$dispatcher->add_handler(
111 -system_identifier => "$system_identifier",
112 -handler => \$handler
113 );
114 \$dispatcher->On_Macro_File_Load();
115 ]]>
116 </MACRO>
117 EOT
118 ;
119
120 foreach my $event (@events) {
121
122 print qq{ <MACRO name="$event" key="" lang="PerlScript">
123 <![CDATA[
124 \$dispatcher->$event(\$ActiveDocument);
125 ]]>
126 </MACRO>
127 }
128 }
129
130 print <<EOT
131 </MACROS>
132 EOT
133 ;
134
135
136 sub help {
137 print <<EOT
138 gmcr.pl generates XMetaL .mcr (macro) files.
139
140 Synopsis:
141
142 gmcr.pl [-m] [-g] [-h] sysid module >outfile.mcr
143
144 sysid = The system identifier of the documents to be customized
145 using the module
146 module - The Perl module used to customize XMetaL
147 -f - Add file events (Replaces XMetaL's default file open
148 and save operations)
149 -m - Add mouse events (may slow XMetaL down)
150 -g - Add global macro events
151 -h - Print this help message
152 outfile.mcr - An XMetaL macro file
153
154 The following event types can not be generated using gmcr.pl:
155 * On_Drop_format
156 * On_Drag_Over_format
157 EOT
158 ;
159 exit 1;
160 }