Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use Mo instead of Moo and ship it

  • Loading branch information...
commit 535e7d983c6892a395f99c969a61978e952d8dc3 1 parent 069fa11
@tadzik authored
Showing with 53 additions and 12 deletions.
  1. +37 −0 lib/Mo.pm
  2. +16 −12 lib/Quiz.pm
View
37 lib/Mo.pm
@@ -0,0 +1,37 @@
+use 5.010;
+package Mo;
+use strict;
+use warnings;
+
+our $VERSION = '0.11';
+
+use base 'Exporter';
+
+our @EXPORT = qw(extends has);
+
+sub import {
+ my $class = $_[0];
+ strict->import;
+ warnings->import;
+ no strict 'refs';
+ push @{caller.'::ISA'}, $class;
+ goto &Exporter::import;
+}
+
+sub new {
+ my $class = shift;
+ my $self = bless {@_}, $class;
+ if ($self->can('BUILD')) { $self->BUILD }
+ return $self;
+}
+
+no strict 'refs';
+
+sub has {
+ my $name = shift;
+ *{caller."::$name"} = sub { @_-1 ? $_[0]->{$name} = $_[1] : $_[0]->{$name} };
+}
+
+sub extends { @{caller.'::ISA'} = $_[0] }
+
+1;
View
28 lib/Quiz.pm
@@ -6,25 +6,29 @@
use JSON::XS;
use File::Slurp 'slurp';
- use Moo;
- has db => (is => 'ro', default => sub { 'db.json' });
- # int -> id pytania
- has states => (is => 'ro', default => sub { [] });
- # id pytania -> obiekt Question
- has questions => (is => 'ro', default => sub { {} });
- has answers => (is => 'ro', default => sub { {} });
+ use Mo;
+ has 'db';
+ has 'states'; # int -> id pytania
+ has 'questions'; # id pytania -> obiekt Question
+ has 'answers';
{
package Question;
- use Moo;
- has state => ( is => 'ro' );
- has question => ( is => 'ro' );
- has yes => ( is => 'ro' );
- has no => ( is => 'ro' );
+ use Mo;
+ has 'state';
+ has 'question';
+ has 'yes';
+ has 'no';
}
sub BUILD {
my $self = shift;
+ # defaults
+ $self->db // $self->db('db.json');
+ $self->states([]);
+ $self->questions({});
+ $self->answers({});
+
my $data = decode_json(slurp($self->db));
my $stateiter = 1;
Please sign in to comment.
Something went wrong with that request. Please try again.