HTML::Dojo - Provides the Dojo JavaScript / AJAX distribution 0.4.3 files.


HTML-Dojo documentation Contained in the HTML-Dojo distribution.

Index


Code Index:

NAME

Top

HTML::Dojo - Provides the Dojo JavaScript / AJAX distribution 0.4.3 files.

SYNOPSIS

Top

    use HTML::Dojo;

    my $dojo = HTML::Dojo->new;

    my @editions = $dojo->editions();

    my @files = $dojo->list( \%options );

    my $data = $dojo->file( $filename, \%options );

DESCRIPTION

Top

HTML::Dojo provides files from the Dojo JavaScript / AJAX distribution.

These files include the dojo.js file, the entire src directory, the iframe_history.html file, various *.swf files, the LICENSE, README and build.txt files.

METHODS

Top

new

    $dojo->new( %options );

This returns a HTML::Dojo object.

Optional arguments are:

edition

editions

    $dojo->editions();

This method returns a list of all available editions. Each edition represents a distribution file made available by the Dojo Foundation, and as such is subject to change with each release.

The current editions available are:

ajax
charting
dojoWebsite
editor
event_and_io
kitchen_sink
lfx
moxie
storage
widget
xdomain-ajax

list

    $dojo->list( \%options );

Returns an array-ref of all files available.

Optional arguments are:

edition
directories, include directory names, default 0
files, include ordinary-file names, default 1

file

    $dojo->file( $filename, \%options )

Returns the contents of the named file.

Optional arguments are:

edition, default ajax.

SEE ALSO

Top

http://dojotoolkit.org, HTML::Prototype

SUPPORT

Top

Catalyst mailing list:

    http://lists.rawmode.org/mailman/listinfo/catalyst

AUTHOR

Top

Carl Franks, <cfranks@cpan.org>

COPYRIGHT AND LICENSE

Top


HTML-Dojo documentation Contained in the HTML-Dojo distribution.
package HTML::Dojo;

use 5.006;
use strict;
use warnings;
use Carp qw/ croak /;

our $VERSION = '0.0403.0';

our $COMMON_DATA;
our $EDITIONS_DATA;
our $SRC_DATA;

sub new {
    my ($class, %args) = @_;
    
    if (exists $args{edition}) {
        croak "invalid edition"
            unless grep { $_ eq $args{edition} } $class->editions;
    }
    
    return bless \%args, $class;
}

# support a :no_files import flag, so that build_packages.pl can 
# use us without locking the sub-module .pm files

sub import {
    my $class   = shift;
    my $require = 1;
    
    for (@_) {
        if ($_ eq ':no_files') {
            $require = 0;
        }
        else {
            croak "unknown import option: $_";
        }
    }
    
    if ($require == 1) {
        require HTML::Dojo::common;
        require HTML::Dojo::editions;
        require HTML::Dojo::src;
    }
}

sub editions {
    return qw/
        ajax
        charting
        editor
        event_and_io
        kitchen_sink
        src
        storage
        widget
        xdomain-ajax
    /;
}

sub list {
    my ($self, $opt) = @_;
    
    my $edition = $opt->{edition} || $self->{edition} || 'ajax';
    $opt->{directories} = 0 if ! exists $opt->{directories};
    $opt->{files}       = 1 if ! exists $opt->{files};
    
    croak "too many arguments, options must be a hash-ref" if @_ > 2;
    
    croak "invalid edition"
        unless grep { $_ eq $edition } $self->editions;
    
    my @files;
    
    push @files, $self->_editions_files( $edition )
        if $opt->{files};
    
    push @files, $self->_common_files()
        if $opt->{files};
    
    push @files, $self->_list_src( $edition, $opt );
    
    return \@files;
}

sub _list_src {
    my ($self, $edition, $opt) = @_;
    my @files;
    
    if (! defined $SRC_DATA) {
        local $/;
        $SRC_DATA = eval { package HTML::Dojo::src; <DATA> };
    }
    # use look-ahead so the __CPAN_ line isn't removed
    my @data = split /^(?=__CPAN_[^\n]+\r?\n)/m, $SRC_DATA;
    
    for (@data) {
        next unless length;
        
        croak "unknown format: '$_'" unless /__CPAN_(DIR|FILE)__ ([^\r\n]+)/;

        if ($1 eq 'DIR' && $opt->{directories}) {
            push @files, $2;
        }
        
        if ($1 eq 'FILE' && $opt->{files}) {
            push @files, $2;
        }
    }
    return @files;
}

sub file {
    my ($self, $filename, $opt) = @_;
    
    my $edition = $opt->{edition} || $self->{edition} || 'ajax';
    
    croak "too many arguments, options must be a hash-ref" if @_ > 3;
    
    croak "invalid edition"
        unless grep { $_ eq $edition } $self->editions;
    
    if (grep { $filename eq $_ } $self->_common_files) {
        return $self->_file_common( $filename );
    }
    elsif (grep { $filename eq $_ } $self->_editions_files) {
        return $self->_file_edition( $filename, $edition );
    }
    else {
        return $self->_file_src( $filename );
    }
}

sub _file_common {
    my ($self, $filename) = @_;
    
    if (! defined $COMMON_DATA) {
        local $/;
        no warnings 'once';
        $COMMON_DATA = eval { package HTML::Dojo::common; <DATA> };
    }
    # use look-ahead so the __CPAN_ line isn't removed
    my @data = split /^(?=__CPAN_[^\n]+\r?\n)/m, $COMMON_DATA;
    
    for (@data) {
        next unless length;
        
        croak "unknown format: '$_'" 
            unless s/__CPAN_COMMON__ ([^\r\n]+)\r?\n//;
        
        next unless $1 eq $filename;
        
        chomp;
        return $_;
    }
    
    croak "didn't find data for file '$filename''";
}

sub _file_edition {
    my ($self, $filename, $edition) = @_;
    
    if (! defined $EDITIONS_DATA) {
        local $/;
        no warnings 'once';
        $EDITIONS_DATA = eval { package HTML::Dojo::editions; <DATA> };
    }
    # use look-ahead so the __CPAN_ line isn't removed
    my @data = split /^(?=__CPAN_[^\n]+\r?\n)/m, $EDITIONS_DATA;
    
    for (@data) {
        next unless length;
        
        croak "unknown format" 
            unless s/__CPAN_EDITION__ (\w+) ([^\r\n]+)\r?\n//;
        
        next unless $1 eq $edition;
        next unless $2 eq $filename;
        
        chomp;
        return $_;
    }
    
    croak "didn't find data for file '$filename', edition '$edition'";
}

sub _file_src {
    my ($self, $filename) = @_;
    
    if (! defined $SRC_DATA) {
        local $/;
        $SRC_DATA = eval { package HTML::Dojo::src; <DATA> };
    }
    # use look-ahead so the __CPAN_ line isn't removed
    my @data = split /^(?=__CPAN_[^\n]+\r?\n)/m, $SRC_DATA;
    
    for (@data) {
        next unless length;
        
        croak "unknown format" unless s/__CPAN_(DIR|FILE)__ ([^\r\n]+)\r?\n//;
        
        next unless $1 eq 'FILE' && $2 eq $filename;
        
        chomp;
        return $_;
    }
    
    croak "didn't find data for file '$filename'";
}

# internals used by build_packages.pl

sub _editions_files {
    return qw/
        dojo.js
        build.txt
    /;
}

sub _common_files {
    return qw/
        iframe_history.html
        flash6_gateway.swf
        storage_dialog.swf
        Storage_version6.swf
        Storage_version8.swf
        README
        LICENSE
    /;
}

1;