This file contains hidden or 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
ref($_) eq 'HASH" && defined($_->{'$id'}) && defined($_->{'$ref'}) |
This file contains hidden or 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
foreach my $object_type ($self->objectmanager->registered_types) { | |
$self->objectmanager->meta_for($object_type => Moose::Meta::Class->create( | |
'App::Object::' . $object_type, | |
{ | |
methods => $self->objectmanager->get_methods_for($object_type), | |
attributes => $self->objectmanager->get_attributes_for($object_type), | |
superclasses => ['App::Object'], | |
roles => [ 'App::Object::Generated', $self->objectmanager->roles_for($object_type) ], | |
} | |
); |
This file contains hidden or 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
$self->objectmanager->add_sub_for( | |
object => $object_type, | |
object_method => $method_name, | |
method => sub { | |
if(my $m = shift->app->jsp->can($method_name)) { | |
return $m->(@_); | |
} | |
}, | |
); |
This file contains hidden or 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
if(my $upload = $self->req->upload('myfile')) { | |
my $filename = $upload->filename; | |
my $asset; | |
if(ref($upload->asset) ne 'Mojo::Upload::File') { | |
$asset = Mojo::Asset::File->new(path => POSIX::tmpnam); | |
$asset->add_chunk($upload->asset->slurp); | |
} else { | |
$asset = $upload->asset; | |
} |
This file contains hidden or 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
package My::Object; | |
use Moose (); | |
use Moose::Exporter; | |
use namespace::autoclean; | |
use My::Meta::Types; | |
use My::Meta::AttributeTraits; | |
Moose::Exporter->setup_import_methods( | |
also => 'Moose', | |
); |
This file contains hidden or 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
# If you look at my Monger repository, imagine the following snippet being stuck in | |
# Monger.pm | |
BEGIN { | |
Moose::Meta::Class->meta->make_mutable; | |
Moose::Meta::Class->meta->add_before_method_modifier('make_immutable', sub { | |
my $self = shift; | |
my $name = $self->name; | |
# apply the dbref role if, and only if, we're a monger::document |
This file contains hidden or 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
use Data::Dumper; | |
sub deflate { | |
my $self = shift; | |
my $doc = {}; | |
foreach my $attribute ($self->meta->get_all_attributes) { | |
# here be dragons, type checks, trait checks, and more | |
$doc->{$attribute->name} = $attribute->get_value($self); | |
} |
This file contains hidden or 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
sub somecontroller { | |
my $self = shift; | |
my $foo = My::App::PaintBucket->new(); | |
$foo->paint(what => 'wall') || die My::App::Exception::NoPaintException->new(caller(1)); | |
} | |
This file contains hidden or 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
var myPlugin = new Extension({ 'foo': 'bar'}); | |
myPlugin.hook('render_filter', function(output) { | |
output.replace('foo','bar'); | |
return output; | |
}); | |
app.register(myPlugin); |
This file contains hidden or 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
package My::Plugin; | |
use strict; | |
use warnings; | |
use base 'TheApp::Plugin::Base'; | |
sub register { | |
my $self = shift; | |
my $app = shift; | |
$self->hook(render_filter => sub { s/foo/bar/ and return $_ }); |