Acme-Gtk2-Ex-Builder
view release on metacpan or search on metacpan
lib/Acme/Gtk2/Ex/Builder.pm view on Meta::CPAN
};
$_code->() if defined $_code;
$self->_current_pop;
};
$code->();
return $self;
}
sub _warn {
my $syntax = shift;
sub { warn "you cannot call '$syntax' directly" };
}
*_widget = _warn 'widget';
*_info = _warn 'info';
*_on = _warn 'on';
*_set = _warn 'set';
*_prop = _warn 'prop';
sub widget { goto &_widget }
sub info { goto &_info }
sub on { goto &_on }
sub set { goto &_set }
sub prop { goto &_prop }
1;
=pod
=encoding utf-8
=head1 NAME
Acme::Gtk2::Ex::Builder - Funny Gtk2 Interface Design Module
=head1 VERSION
version 0.008
=head1 SYNOPSIS
use strict;
use warnings;
use Gtk2 -init;
use Acme::Gtk2::Ex::Builder;
my $app = build {
widget Window => contain {
info id => 'window';
set title => 'Awesome App';
set default_size => 200, 100;
set position => 'center';
on delete_event => sub { Gtk2->main_quit; };
widget Button => contain {
set label => 'Action';
on clicked => sub { say 'Seoul Perl Mongers!' };
};
};
};
$app->find('window')->show_all;
Gtk2->main;
=head1 METHODS
=head2 find
Find and get widget by ID.
You can find widget only you set C<id> with C<info> function.
my $app = build {
widget Window => contain {
info id => 'my-window';
};
};
my $window = $app->find('my-window');
=head1 FUNCTIONS
=head2 build
This function acts like ordinary "new" method.
It is exported by default and returns L<Acme::Gtk2::Ex::Builder> object.
It can contains several C<widget> functions.
my $app = build {
widget Window;
widget Dialog;
widget FileChooser;
widget VBox;
};
=head2 widget
This function creates the Gtk2 widget.
In fact when you use this, C<< Gtk2::XXX->new >> will be called.
See L<Gtk2> and Gtk2 API reference.
Following code will call C<< Gtk2::Window->new >>.
my $app = build {
widget Window;
};
If you need more children widgets,
use C<contain>, then call C<widget> again and again.
my $app = build {
widget Window contain => {
widget HBox => contain {
widget Button;
widget Button;
widget Button;
};
};
( run in 0.421 second using v1.01-cache-2.11-cpan-ff9377addf4 )