Skip to content

Instantly share code, notes, and snippets.

@nicomen
Created February 1, 2014 01:15
Show Gist options
  • Save nicomen/8746556 to your computer and use it in GitHub Desktop.
Save nicomen/8746556 to your computer and use it in GitHub Desktop.
package Invoke::IfObject;
use strict;
use warnings FATAL => 'all';
use Scalar::Util qw(blessed);
#use Exporter 5.57 qw(import);
our @EXPORT = qw($then);
sub AUTOLOAD {
return;
}
our $then = sub { return blessed($_[0]) ? $_[0] : bless {} };
package main;
use v5.10;
use strict;
use warnings;
use Invoke::IfObject
use Mojo::DOM;
my $d = Mojo::DOM->new('<h1>title</h1>');
say $d->find('h1')->first->text;
say $d->find('h2')->first->$then->text || 'No title';
say $d->find('h2')->first->text || 'No title';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment