Skip to content

Instantly share code, notes, and snippets.

View benvanstaveren's full-sized avatar

Ben van Staveren benvanstaveren

View GitHub Profile
[
{
"title" : "Technical Engineer: U.S.S.R.",
"id" : 127,
"ident" : "mechanicEngineer0"
},
{
"title" : "maxPiercingSeries",
"id" : 32,
"ident" : "maxPiercingSeries"
@benvanstaveren
benvanstaveren / DisqusBridge.pl
Created April 22, 2011 01:05
A little example for using Mojolicious::Lite, Mojolicious::Plugin::Disqus and Net::Disqus
#!/usr/bin/env perl
use Mojolicious::Lite;
use Try::Tiny;
plugin 'disqus', { 'api_secret' => 'getyourownsecretplease', pass_api_errors => 1 };
# This, of course, is total and utter overkill for something like this,
# but I figured if I'm going to write demonstration code, might as well
# go the whole hog.
plugin 'mongodb', { 'database' => 'disqusbridge' };
foreach my $key keys %hash {
print "key is: $key\n";
}
print "key is: $_" for keys %hash;
print('key is: ', $key, "\n") for(keys(%hash));
var myPlugin = new Extension({ 'foo': 'bar'});
myPlugin.hook('render_filter', function(output) {
output.replace('foo','bar');
return output;
});
app.register(myPlugin);
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 $_ });
sub somecontroller {
my $self = shift;
my $foo = My::App::PaintBucket->new();
$foo->paint(what => 'wall') || die My::App::Exception::NoPaintException->new(caller(1));
}
@benvanstaveren
benvanstaveren / gist:1007128
Created June 3, 2011 20:41
deflating Moose class to something suitable for using in MongoDB
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);
}
# 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