FBP
view release on metacpan or search on metacpan
lib/FBP/Parser.pm view on Meta::CPAN
package FBP::Parser;
use 5.008005;
use strict;
use warnings;
use Params::Util ();
use XML::SAX::Base ();
use FBP ();
our $VERSION = '0.41';
our @ISA = 'XML::SAX::Base';
# Object XML class to Perl class mapping
my %OBJECT_CLASS = (
Project => 'FBP::Project',
Dialog => 'FBP::Dialog',
Frame => 'FBP::Frame',
Panel => 'FBP::FormPanel',
# Direct Mappings
wxAnimationCtrl => 'FBP::AnimationCtrl',
wxBitmapButton => 'FBP::BitmapButton',
wxBoxSizer => 'FBP::BoxSizer',
wxButton => 'FBP::Button',
wxCalendarCtrl => 'FBP::CalendarCtrl',
wxCheckBox => 'FBP::CheckBox',
wxChoice => 'FBP::Choice',
wxChoicebook => 'FBP::Choicebook',
wxComboBox => 'FBP::ComboBox',
wxColourPickerCtrl => 'FBP::ColourPickerCtrl',
wxDatePickerCtrl => 'FBP::DatePickerCtrl',
wxDirPickerCtrl => 'FBP::DirPickerCtrl',
wxFilePickerCtrl => 'FBP::FilePickerCtrl',
wxFlexGridSizer => 'FBP::FlexGridSizer',
wxFontPickerCtrl => 'FBP::FontPickerCtrl',
wxGauge => 'FBP::Gauge',
wxGenericDirCtrl => 'FBP::GenericDirCtrl',
wxGrid => 'FBP::Grid',
wxGridBagSizer => 'FBP::GridBagSizer',
wxGridSizer => 'FBP::GridSizer',
wxHtmlWindow => 'FBP::HtmlWindow',
wxHyperlinkCtrl => 'FBP::HyperlinkCtrl',
wxListbook => 'FBP::Listbook',
wxListBox => 'FBP::ListBox',
wxListCtrl => 'FBP::ListCtrl',
wxMenu => 'FBP::Menu',
wxMenuBar => 'FBP::MenuBar',
wxMenuItem => 'FBP::MenuItem',
wxNotebook => 'FBP::Notebook',
wxPanel => 'FBP::Panel',
wxRadioBox => 'FBP::RadioBox',
wxRadioButton => 'FBP::RadioButton',
wxRichTextCtrl => 'FBP::RichTextCtrl',
wxScrollBar => 'FBP::ScrollBar',
wxScrolledWindow => 'FBP::ScrolledWindow',
wxSearchCtrl => 'FBP::SearchCtrl',
wxSlider => 'FBP::Slider',
wxSpinButton => 'FBP::SpinButton',
wxSpinCtrl => 'FBP::SpinCtrl',
wxSplitterWindow => 'FBP::SplitterWindow',
wxStaticBitmap => 'FBP::StaticBitmap',
wxStaticBoxSizer => 'FBP::StaticBoxSizer',
wxStaticText => 'FBP::StaticText',
wxStaticLine => 'FBP::StaticLine',
wxStatusBar => 'FBP::StatusBar',
wxStdDialogButtonSizer => 'FBP::StdDialogButtonSizer',
wxTextCtrl => 'FBP::TextCtrl',
wxToggleButton => 'FBP::ToggleButton',
wxToolBar => 'FBP::ToolBar',
wxTreeCtrl => 'FBP::TreeCtrl',
# Special Mappings
choicebookpage => 'FBP::ChoicebookPage',
gbsizeritem => 'FBP::GridBagSizerItem',
listbookpage => 'FBP::ListbookPage',
notebookpage => 'FBP::NotebookPage',
sizeritem => 'FBP::SizerItem',
submenu => 'FBP::Menu',
separator => 'FBP::MenuSeparator',
spacer => 'FBP::Spacer',
splitteritem => 'FBP::SplitterItem',
tool => 'FBP::Tool',
toolSeparator => 'FBP::ToolSeparator',
CustomControl => 'FBP::CustomControl',
);
######################################################################
# Constructor and Accessors
sub new {
my $class = Params::Util::_CLASS(shift);
my $parent = Params::Util::_INSTANCE(shift, 'FBP');
unless ( $parent ) {
die("Did not provide a parent FBP object");
}
# Create the basic parsing object
my $self = bless {
raw => 0,
stack => [ $parent ],
}, $class;
$self;
}
sub parent {
$_[0]->{stack}->[-1];
}
######################################################################
# Generic SAX Handlers
sub start_element {
my $self = shift;
my $element = shift;
# We don't support namespaces
if ( $element->{Prefix} ) {
die(__PACKAGE__ . ' does not support XML namespaces');
}
# Flatten the Attributes into a simple hash
my %hash = map { $_->{LocalName}, $_->{Value} }
grep { $_->{Value} =~ s/^\s+//; $_->{Value} =~ s/\s+$//; 1; }
grep { ! $_->{Prefix} }
values %{$element->{Attributes}};
# Handle off to the appropriate tag-specific handler
my $handler = 'start_element_' . lc $element->{LocalName};
unless ( $self->can($handler) ) {
die("No handler for tag $element->{LocalName}");
( run in 0.753 second using v1.01-cache-2.11-cpan-39bf76dae61 )