Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Craftworks
committed
Feb 24, 2011
1 parent
54ef2d2
commit 5daab38
Showing
12 changed files
with
378 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package Airy::Attribute::Container; | ||
|
||
use strict; | ||
use warnings; | ||
use parent 'Class::Data::Inheritable'; | ||
|
||
__PACKAGE__->mk_classdata('attributes'); | ||
__PACKAGE__->mk_classdata('classes'); | ||
__PACKAGE__->attributes({}); | ||
__PACKAGE__->classes({}); | ||
|
||
sub set { | ||
my ($class, $package, $code, @attrs) = @_; | ||
|
||
push @{ $class->attributes->{ $package } }, +{ | ||
'code' => $code, | ||
'attrs' => \@attrs, | ||
}; | ||
|
||
for my $attr ( @attrs ) { | ||
$attr =~ /^(\w+)/o; | ||
$class->classes->{ $1 }++; | ||
} | ||
} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package Airy::View::JSON; | ||
|
||
use Airy; | ||
use base 'Airy::View'; | ||
use JSON; | ||
|
||
sub render { | ||
my ($self, $vars) = @_; | ||
|
||
my $json = encode_json($vars); | ||
|
||
return $json; | ||
} | ||
|
||
sub render_web { | ||
my ($self, $stash) = @_; | ||
no warnings 'once'; | ||
my $c = $Airy::CONTEXT; | ||
|
||
# TODO support callback switching | ||
my $cb_param = ( 1 || 'allow_callback' ) | ||
? ( 'callback' ) : undef; | ||
my $cb = $cb_param ? $c->req->param($cb_param) : undef; | ||
|
||
my $encoding = $c->encoding->mime_name; | ||
my $body; | ||
|
||
# add UTF-8 BOM if the client is Safari | ||
if ( $encoding eq 'UTF-8' ) { | ||
my $user_agent = $c->req->user_agent || ''; | ||
if ( $user_agent =~ m/\bSafari\b/ && $user_agent !~ m/\bChrome\b/ ) { | ||
$body = "\xEF\xBB\xBF"; | ||
} | ||
} | ||
|
||
$body .= "$cb(" if $cb; | ||
$body .= $self->render($stash->{'json'}); | ||
$body .= ");" if $cb; | ||
|
||
$c->res->body($body); | ||
|
||
if ( ($c->req->user_agent || '') =~ /Opera/ ) { | ||
$c->res->content_type("application/x-javascript; charset=$encoding"); | ||
} | ||
else { | ||
$c->res->content_type("application/json; charset=$encoding"); | ||
} | ||
} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.