| 1 | package App::XUL::XML; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use App::XUL::Object; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Time::HiRes qw(time); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||
| 6 | 1 | our $AUTOLOAD; | |||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | # this is 1 if the module is loaded from within a running server! | ||||||||||||||||||||||||||||||||
| 9 | 1 | our $RunInsideServer = 0; | |||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||
| 11 | # regular expression that matches a HTML5 tagname | ||||||||||||||||||||||||||||||||
| 12 | 1 | my $HTMLTagRegex = | |||||||||||||||||||||||||||||||
| 13 | '^('. | ||||||||||||||||||||||||||||||||
| 14 | join('|', | ||||||||||||||||||||||||||||||||
| 15 | qw(a abbr acronym address applet area article aside audio | ||||||||||||||||||||||||||||||||
| 16 | b base basefont bdo big blockquote body br button | ||||||||||||||||||||||||||||||||
| 17 | canvas caption center cite code col colgroup command | ||||||||||||||||||||||||||||||||
| 18 | datalist dd del details dfn dir div dl dt | ||||||||||||||||||||||||||||||||
| 19 | em embed fieldset figcaption figure font footer form frame frameset | ||||||||||||||||||||||||||||||||
| 20 | h1 h2 h3 h4 h5 h6 head header hgroup hr html | ||||||||||||||||||||||||||||||||
| 21 | i iframe img input ins | ||||||||||||||||||||||||||||||||
| 22 | keygen kbd | ||||||||||||||||||||||||||||||||
| 23 | label legend li link | ||||||||||||||||||||||||||||||||
| 24 | map mark menu meta meter | ||||||||||||||||||||||||||||||||
| 25 | nav noframes noscript | ||||||||||||||||||||||||||||||||
| 26 | object ol optgroup option output | ||||||||||||||||||||||||||||||||
| 27 | p param pre progress | ||||||||||||||||||||||||||||||||
| 28 | q | ||||||||||||||||||||||||||||||||
| 29 | rp rt ruby | ||||||||||||||||||||||||||||||||
| 30 | s samp script section select small source span strike strong style | ||||||||||||||||||||||||||||||||
| 31 | sub summary sup | ||||||||||||||||||||||||||||||||
| 32 | table tbody td textarea tfoot th thead time title tr tt | ||||||||||||||||||||||||||||||||
| 33 | u ul | ||||||||||||||||||||||||||||||||
| 34 | var | ||||||||||||||||||||||||||||||||
| 35 | video | ||||||||||||||||||||||||||||||||
| 36 | wbr | ||||||||||||||||||||||||||||||||
| 37 | xmp)).')$'; | ||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||
| 39 | 1 | my $XULTagRegex = | |||||||||||||||||||||||||||||||
| 40 | '^('. | ||||||||||||||||||||||||||||||||
| 41 | join('|', | ||||||||||||||||||||||||||||||||
| 42 | qw(action arrowscrollbox | ||||||||||||||||||||||||||||||||
| 43 | bbox binding bindings box broadcaster broadcasterset button browser | ||||||||||||||||||||||||||||||||
| 44 | caption checkbox colorpicker column columns command commandset conditions content | ||||||||||||||||||||||||||||||||
| 45 | deck description dialog dialogheader | ||||||||||||||||||||||||||||||||
| 46 | editor | ||||||||||||||||||||||||||||||||
| 47 | grid grippy groupbox | ||||||||||||||||||||||||||||||||
| 48 | hbox | ||||||||||||||||||||||||||||||||
| 49 | iframe image | ||||||||||||||||||||||||||||||||
| 50 | key keyset | ||||||||||||||||||||||||||||||||
| 51 | label listbox listcell listcol listcols listhead listheader listitem | ||||||||||||||||||||||||||||||||
| 52 | member menu menubar menuitem menulist menupopup menuseparator | ||||||||||||||||||||||||||||||||
| 53 | observes overlay | ||||||||||||||||||||||||||||||||
| 54 | page popup popupset preference preferences prefpane prefwindow progressmeter | ||||||||||||||||||||||||||||||||
| 55 | radio radiogroup resizer richlistbox richlistitem row rows rule | ||||||||||||||||||||||||||||||||
| 56 | script scrollbar scrollbox scrollcorner separator spacer splitter stack | ||||||||||||||||||||||||||||||||
| 57 | statusbar statusbarpanel stringbundle stringbundleset | ||||||||||||||||||||||||||||||||
| 58 | tab tabbrowser tabbox tabpanels tabs template textnode textbox titlebar | ||||||||||||||||||||||||||||||||
| 59 | toolbar toolbarbutton toolbaritem toolbarpalette toolbarseparator | ||||||||||||||||||||||||||||||||
| 60 | toolbarset toolbarspacer toolbarspring toolbox tooltip tree | ||||||||||||||||||||||||||||||||
| 61 | treecell treechildren treecol treecols treeitem treerow treeseparator triple | ||||||||||||||||||||||||||||||||
| 62 | vbox | ||||||||||||||||||||||||||||||||
| 63 | window wizard wizardpage)).')$'; | ||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||
| 65 | # function for XML creation, | ||||||||||||||||||||||||||||||||
| 66 | # e.g. Window('attr1'='val1', 'attr2'='val2', 'content...'); | ||||||||||||||||||||||||||||||||
| 67 | sub AUTOLOAD | ||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | { | ||||||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: not called CC=21 SCAR=61.4
| |||||||||||||||||||||||||||||||||
| 69 | 0 | my (@rest) = @_; | |||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | return if $AUTOLOAD =~ /::DESTROY$/; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||
| 73 | 0 | my $tagname = $AUTOLOAD; | |||||||||||||||||||||||||||||||
| 74 | 0 | $tagname =~ s/.*://; | |||||||||||||||||||||||||||||||
| 75 | #print "($tagname)\n"; | ||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | if ($RunInsideServer && $tagname eq 'ID') { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$RunInsideServer and $tagname eq "ID"
MC/DC0%0/2
$RunInsideServer and $tagname eq "ID"
$RunInsideServer
$tagname eq "ID"
Truth table0%0/3
A and B
A= $RunInsideServerB= $tagname eq "ID"
| |||||||||||||||||||||||||||||||||
| 78 | 0 | my ($id) = @rest; | |||||||||||||||||||||||||||||||
| 79 | 0 | return App::XUL::Object->new($id); | |||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||
| 81 | ▶ | elsif ($tagname =~ /$HTMLTagRegex/i || $tagname =~ /$XULTagRegex/i) { | |||||||||||||||||||||||||||||||
|
Condition0%0/3
$tagname =~ /$HTMLTagRegex/i or $tagname =~ /$XULTagRegex/i
MC/DC0%0/2
$tagname =~ /$HTMLTagRegex/i or $tagname =~ /$XULTagRegex/i
$tagname =~ /$HTMLTagRegex/i
$tagname =~ /$XULTagRegex/i
Truth table0%0/3
A or B
A= $tagname =~ /$HTMLTagRegex/iB= $tagname =~ /$XULTagRegex/i
| |||||||||||||||||||||||||||||||||
| 82 | 0 | $tagname = lcfirst $tagname; | |||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | $tagname = 'html:'.$tagname | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$tagname =~ /$HTMLTagRegex/i and not $tagname =~ /$XULTagRegex/i
MC/DC0%0/2
$tagname =~ /$HTMLTagRegex/i and not $tagname =~ /$XULTagRegex/i
$tagname =~ /$HTMLTagRegex/i
not $tagname =~ /$XULTagRegex/i
Truth table0%0/3
A and not(B)
A= $tagname =~ /$HTMLTagRegex/iB= not $tagname =~ /$XULTagRegex/i
| |||||||||||||||||||||||||||||||||
| 84 | if $tagname =~ /$HTMLTagRegex/i && $tagname !~ /$XULTagRegex/i; | ||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||
| 86 | 0 | my %attribs = (); | |||||||||||||||||||||||||||||||
| 87 | 0 | my $content = ''; | |||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | foreach (my $i = 0; $i < scalar @rest; $i++) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 89 | 0 | my $attrname = $rest[$i]; | |||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | if ($attrname =~ /^[a-zA-Z0-9\:]+$/ && $i < scalar @rest -1) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$attrname =~ /^[a-zA-Z0-9\:]+$/ and $i < scalar @rest - 1
MC/DC0%0/2
$attrname =~ /^[a-zA-Z0-9\:]+$/ and $i < scalar @rest - 1
$attrname =~ /^[a-zA-Z0-9\:]+$/
$i < scalar @rest - 1
Truth table0%0/3
A and B
A= $attrname =~ /^[a-zA-Z0-9\:]+$/B= $i < scalar @rest - 1
| |||||||||||||||||||||||||||||||||
| 91 | 0 | my $attrvalue = $rest[$i+1]; | |||||||||||||||||||||||||||||||
| 92 | 0 | $attribs{$attrname} = $attrvalue; | |||||||||||||||||||||||||||||||
| 93 | 0 | $i++; | |||||||||||||||||||||||||||||||
| 94 | } else { | ||||||||||||||||||||||||||||||||
| 95 | 0 | $content .= $attrname; | |||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||
| 99 | # autogenerate ID if not provided | ||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | unless (exists $attribs{'id'}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 101 | 0 | $attribs{'id'} = 'e'.time(); | |||||||||||||||||||||||||||||||
| 102 | 0 | $attribs{'id'} =~ s/[^\w\d]//g; | |||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | if ($tagname eq 'button' && ref $attribs{'oncommand'} eq 'CODE') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$tagname eq "button" and ref $attribs{"oncommand"} eq "CODE"
MC/DC0%0/2
$tagname eq "button" and ref $attribs{"oncommand"} eq "CODE"
$tagname eq "button"
ref $attribs{"oncommand"} eq "CODE"
Truth table0%0/3
A and B
A= $tagname eq "button"B= ref $attribs{"oncommand"} eq "CODE"
| |||||||||||||||||||||||||||||||||
| 106 | # add eventhandler to App::XUL bindings | ||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | if ($RunInsideServer) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 108 | 0 | main::bind($attribs{'id'}, 'click', $attribs{'oncommand'}); | |||||||||||||||||||||||||||||||
| 109 | } else { | ||||||||||||||||||||||||||||||||
| 110 | 0 | App::XUL::bind($attribs{'id'}, 'click', $attribs{'oncommand'}); | |||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||
| 112 | 0 | $attribs{'oncommand'} = "AppXUL.send('click','".$attribs{'id'}."');"; | |||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | if ($tagname eq 'window') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | $attribs{'title'} = $App::XUL::Singleton->{'name'} unless exists $attribs{'title'}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | $attribs{'width'} = '800' unless exists $attribs{'width'}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | $attribs{'height'} = '200' unless exists $attribs{'height'}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||
| 119 | 0 | $attribs{'xmlns'} = 'http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul'; | |||||||||||||||||||||||||||||||
| 120 | 0 | $attribs{'xmlns:html'} = 'http://www.w3.org/1999/xhtml'; | |||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||
| 122 | 0 | $attribs{'onclose'} = "quit(); return false;"; | |||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||
| 124 | 0 | $content = '<script src="AppXUL.js"/>'.$content; | |||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||
| 127 | # create and return XML string | ||||||||||||||||||||||||||||||||
| 128 | return | ||||||||||||||||||||||||||||||||
| 129 | '<'.$tagname. | ||||||||||||||||||||||||||||||||
| 130 | (scalar keys %attribs ? | ||||||||||||||||||||||||||||||||
| 131 | 0 | ▶ | ' '.join(' ', map { $_.'="'.$attribs{$_}.'"' } keys %attribs) : | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 132 | ''). | ||||||||||||||||||||||||||||||||
| 133 | (length $content ? | ||||||||||||||||||||||||||||||||
| 134 | '>'.$content.'</'.$tagname : | ||||||||||||||||||||||||||||||||
| 135 | '/'). | ||||||||||||||||||||||||||||||||
| 136 | '>'; | ||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||
| 140 | 1 | 1; | |||||||||||||||||||||||||||||||