ColbyDavis
ColbyDavis
Reputation Top 1%
ColbyDavis Colby
6 Snippets  (138th place)
Published
1 Channel
Created
2 Channels
Following
196 points  (154th place)
Reputation
Serious Code Generator
Junior Popular Coder
Junior Autobiographer
Senior Autobiographer
Junior Famous Coder
Junior Wise Coder

Recent Snippets See all snippets by ColbyDavis

public by ColbyDavis  2019  0  4  0

Test::Mojo methods for cookie checking

Test::Mojo methods for cookie checking: TestMojoCookies
=head2 has_cookie

Returns 1 if cookie is found irrespective of value.

    $rv = $t->has_cookie( $name, $url );

=cut

sub has_cookie{
    my $self        = shift;
    my $cookie_name = shift;
    my $url         = shift;
    
    return 0 unless ( defined $cookie_name && $cookie_name );
    
    my @ah_cookies = 
        $self->ua->cookie_jar->find( Mojo::URL->new( $url ));

    return 0
        if ( ! @ah_cookies || scalar(@ah_cookies)  == 0);
        
    ## Array contains a bunch of Mojo::Cookie::Request objects
    foreach my $k ( @ah_cookies ) {
        my $found_cookie_name = $k->name;
        return 1 if ( $found_cookie_name eq $cookie_name );
    }
    
    return 0;    
}

=head2 get_cookie_value

Returns the value of the cookie and undef on error.

    my $value = $t->get_cookie_value( $name, $url );

=cut

sub get_cookie_value {
    my $self = shift;
    my $cookie_name = shift;
    my $url = shift;
    
    return 0 unless ( defined $cookie_name && $cookie_name );
    
    my @ah_cookies = 
        $self->ua->cookie_jar->find( Mojo::URL->new( $url ));

    return 0
        if ( ! @ah_cookies || scalar(@ah_cookies)  == 0);
        
    ## Array contains a bunch of Mojo::Cookie::Request objects
    foreach my $k ( @ah_cookies ) {
        my $found_cookie_name = $k->name;
        if ( $found_cookie_name eq $cookie_name ) {
            return $k->value;
        }
    }
    
    return undef;
}

;

public by ColbyDavis  149144  0  3  0

Mojo: bug in routes

Mojo: bug in routes: gistfile1.PL
#!/usr/bin/perl
use strict;
use lib qw(lib ../mojo/lib);
 
$ENV{MOJO_APP} ||= 'App';
 
use Mojolicious::Commands; Mojolicious::Commands->start;

package App;
use strict;
use base 'Mojolicious';

sub startup {
	my $self = shift;
	
	my $r = $self->routes;
	$r->route('/test' )->to('test#show'); # OK
	$r->route('/test1')->to(controller => 'test-test', action => 'show'); # OK
	$r->route('/test2')->to('test-test#show'); # ERROR
}

1;

package App::Test;
use strict;
use base 'Mojolicious::Controller';

sub show { shift->render_text('Test!') }

1;

package App::Test::Test;
use strict;
use base 'Mojolicious::Controller';

sub show { shift->render_text('Test Test!') }

1;


;

public by ColbyDavis  160606  0  3  0

Mojolicious::Controller using CGI::Expand

Mojolicious::Controller using CGI::Expand: Perl: Mojolicious
use Mojo::Base 'Mojolicious';
use CGI::Expand;

sub startup
{
   my $self = shift;
   $self->hook(before_dispatch => sub {
        my $c = shift;
        my $hash = CGI::Expand->expand_hash($c->req->params->to_hash);
        $c->param($_ => $hash->{$_}) for keys %$hash;
    });
}

;

public by ColbyDavis  2648  0  4  0

An example showing how to use a Mojo::IOLoop.

An example showing how to use a Mojo::IOLoop.: Mojo::IOLoop-coro-bench.pl
#!/usr/bin/env perl
use Mojolicious::Lite;
use Coro;
use Mojo::IOLoop;

Mojo::IOLoop->recurring(0 => sub {cede});

hook around_dispatch => sub {
  my $next = shift;
  async { $next->() };
};

get '/' => sub {
  my $self = shift;
  my $ua   = Mojo::UserAgent->new;

  # Comment this line out to see the performance difference
  $ua->ioloop->recurring(0 => sub {cede});

  $self->render(
    text => $ua->get('mojolicio.us')->res->dom->html->head->title->text);
};

app->start;

;

public by ColbyDavis  2116  0  3  0

RPM spec file for Mojolicious

RPM spec file for Mojolicious: perl: Mojolicious
Name:           perl-Mojolicious
Version:        3.56
Release:        1%{?dist}
Summary:        A next generation web framework for Perl
License:        Artistic 2.0
Group:          Development/Libraries
URL:            http://mojolicious.org/
Source0:        http://search.cpan.org/CPAN/modules/by-module/Mojolicous/Mojolicious-%{version}.tar.gz
BuildArch:      noarch
BuildRequires:  perl >= 0:5.010, perl(ExtUtils::MakeMaker)
BuildRequires:  perl(Test::Harness), perl(Test::Simple)
BuildRequires:  perl(Time::HiRes), perl(Digest::SHA)
Requires:       perl(:MODULE_COMPAT_%(eval "`%{__perl} -V:version`"; echo $version))

%description
Back in the early days of the web there was this wonderful Perl library
called CGI, many people only learned Perl because of it. It was simple
enough to get started without knowing much about the language and powerful
enough to keep you going, learning by doing was much fun. While most of the
techniques used are outdated now, the idea behind it is not. Mojolicious is
a new attempt at implementing this idea using state of the art technology.

%prep
%setup -q -n Mojolicious-%{version}

%build
%{__perl} Makefile.PL INSTALLDIRS=vendor
make %{?_smp_mflags}

%install
make pure_install PERL_INSTALL_ROOT=$RPM_BUILD_ROOT

find $RPM_BUILD_ROOT -type f -name .packlist -exec rm -f {} \;
find $RPM_BUILD_ROOT -depth -type d -exec rmdir {} 2>/dev/null \;

%{_fixperms} $RPM_BUILD_ROOT/*

%check
make test

%files
%defattr(-,root,root,-)
%doc Changes LICENSE examples README.pod
%{_bindir}/mojo
%{_bindir}/morbo
%{_bindir}/hypnotoad
%{perl_vendorlib}/*
%{_mandir}/man1/*
%{_mandir}/man3/*

%changelog
* Son Nov 11 2012 Ulrich Habel <rhaen@cpan.org> 3.56-1
- updated to upstream version 3.56

* Mon Nov 05 2012 Ulrich Habel <rhaen@cpan.org> 3.54-1
- updated to upstream version 3.54

* Thu Oct 21 2012 Ulrich Habel <rhaen@cpan.org> 3.50-1
- updated to upstream version 3.50

* Thu Oct 09 2012 Ulrich Habel <rhaen@cpan.org> 3.47-1
- updated to upstream version 3.47

* Thu Oct 09 2012 Ulrich Habel <rhaen@cpan.org> 3.45-1
- updated to upstream version 3.45

* Thu Oct 04 2012 Ulrich Habel <rhaen@cpan.org> 3.44-1
- updated to upstream version 3.44

* Wed Sep 14 2012 Ulrich Habel <rhaen@cpan.org> 3.41-1
- updated to upstream version 3.41

* Wed Sep 12 2012 Ulrich Habel <rhaen@cpan.org> 3.40-1
- updated to upstream version 3.40

* Fri Aug 29 2012 Ulrich Habel <rhaen@cpan.org> 3.35-1
- updated to upstream version 3.35

* Fri Apr 06 2012 Ulrich Habel <rhaen@cpan.org> 2.76-1
- updated to upstream version 2.76

* Sat Feb 25 2012 Ulrich Habel <rhaen@cpan.org> 2.53-1
- updated to upstream version 2.53

* Sat Feb 11 2012 Ulrich Habel <rhaen@cpan.org> 2.48-1
- updated to upstream version 2.48

* Thu Jan 26 2012 Ulrich Habel <rhaen@cpan.org> 2.46-1
- updated to upstream version 2.46

* Sun Jan 15 2012 Ulrich Habel <rhaen@cpan.org> 2.43-1
- updated to upstream version 2.43

* Tue Dec 15 2011 Ulrich Habel <uh@br-online.de> 2.37-1
- updated to upstream version 2.37
  

* Tue Nov 29 2011 Ulrich Habel <uh@br-online.de> 2.34-1
- updated to upstream version 2.34

* Tue Aug 23 2011 Ulrich Habel <uh@br-online.de> 1.87-1
- updated to 1.87-1, included perl-Test-Simple as buildreq
  for Test::Builder and Test::More

* Mon Feb  7 2011 Wolfgang Schreiner <wolfgang.schreiner@br-online.de> 1.01-1
- rebuild for BR, build requirement Time::HiRes added

* Fri Jan  7 2011 Yanko Kaneti <yaneti@declera.com> 1.01-1
- Update to latest upstream 1.01.

* Mon Dec 27 2010 Yanko Kaneti <yaneti@declera.com> 1.0-1
- Update to latest upstream 1.0.

* Mon Dec  6 2010 Yanko Kaneti <yaneti@declera.com> 0.999950-1
- Update to latest upstream 0.999950.
  New included experimental web server - hypnotoad.

* Mon Nov 22 2010 Yanko Kaneti <yaneti@declera.com> 0.999941-1
- Latest upstream release.

* Thu Nov 16 2010 Yanko Kaneti <yaneti@declera.com> 0.999940-1
- New upstream release. Turns off IPv6 support. Bugfixes.

* Thu Nov 10 2010 Yanko Kaneti <yaneti@declera.com> 0.999938-1
- New upstream release. MojoX is gone.

* Thu Nov  5 2010 Yanko Kaneti <yaneti@declera.com> 0.999936-1
- New upstream bugfix release.

* Thu Nov  4 2010 Yanko Kaneti <yaneti@declera.com> 0.999935-1
- Latest upstream release.
  http://search.cpan.org/src/KRAIH/Mojolicious-0.999935/Changes

* Mon Aug 20 2010 Yanko Kaneti <yaneti@declera.com> 0.999929-1
- Latest upstream release.
  http://search.cpan.org/src/KRAIH/Mojolicious-0.999929/Changes

* Mon Aug 16 2010 Yanko Kaneti <yaneti@declera.com> 0.999927-1
- Latest upstream release.
  http://search.cpan.org/src/KRAIH/Mojolicious-0.999927/Changes

* Tue Jun 22 2010 Petr Pisar <ppisar@redhat.com> 0.999926-2
- Rebuild against perl-5.12

* Fri Jun 16 2010 Yanko Kaneti <yaneti@declera.com> 0.999926-1
- Latest upstream release.
  http://search.cpan.org/src/KRAIH/Mojolicious-0.999926/Changes

* Fri Jun 11 2010 Yanko Kaneti <yaneti@declera.com> 0.999925-3
- Actually include the examples.

* Fri Jun 11 2010 Yanko Kaneti <yaneti@declera.com> 0.999925-2
- Initial import. Include examples as doc.

* Tue Jun 08 2010 Yanko Kaneti <yaneti@declera.com> 0.999925-1
- Specfile mostly autogenerated by cpanspec 1.78.


;