NAME
JavaScript::Code::Block - A JavaScript Block Element
DESCRIPTION
A block element in javascript is a collection of javascript elements enclosed in brakets.
Example:
{ // a block starts
var a = 42;
var b = "21 is just half the truth.";
{ // another block starts
// ...
} // another block ends
} // a block ends
SYNOPSIS
#!/usr/bin/perl
use strict;
use warnings;
use JavaScript::Code::Block;
use JavaScript::Code::Variable;
my $block1 = JavaScript::Code::Block->new();
my $var1 = JavaScript::Code::Variable->new( name => 'a', value => "Var 1!" );
my $var2 = JavaScript::Code::Variable->new()->name('b')->value("Var 2!");
my $block2 = JavaScript::Code::Block->new();
my $var3 = JavaScript::Code::Variable->new()->name('c')->value("Var 3!");
$block1->add( $var1 );
$block1->add( $var2 )->add( $block2->add( $var3 ) );
$block1->add( JavaScript::Code::Variable->new()->name('d')->value(42) );
print $block1->output;
METHODS
new
$self->add( $element | \@elements )
Adds one or more new element(s) to the block.
$self->add_variable( %args | \%args )
Creates a variable using the arguments and adds it to the the block.
Returns a JavaScript::Code::Variable object.
$self->add_function( %args | \%args )
Creates a function using the arguments and adds it to the the block.
Returns a JavaScript::Code::Function object.
$self->elements( )
Returns a ref-array of all added elements.
$self->output( )
Returns the javascript code for the block.
SEE ALSO
AUTHOR
Sascha Kiefer, esskar@cpan.org
LICENSE
This library is free software, you can redistribute it and/or modify it under the same terms as Perl itself.