Acme-Gtk2-Ex-Builder
view release on metacpan or search on metacpan
lib/Acme/Gtk2/Ex/Builder.pm view on Meta::CPAN
my $signal = shift;
my $_code = shift;
my $data = shift;
if ($self->_current) {
$self->_current->signal_connect( $signal => $_code, $data );
}
};
local *_set = sub {
my $attr = shift;
my @para = @_;
my $method = "set_$attr";
if ($self->_current) {
$self->_current->$method(@para);
}
};
local *_prop = sub {
my $prop = shift;
my $value = shift;
my $method = "set";
if ($self->_current) {
$self->_current->$method($prop, $value);
}
};
$_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;
( run in 1.691 second using v1.01-cache-2.11-cpan-99c4e6809bf )