GithubHelp home page GithubHelp logo

mo-pm's Introduction

Name

Mo - Micro Objects. Mo is less.

Synopsis

package Less;
use Mo;
extends 'Nothing';

has something => ();

Description

use Mo. Mo is less. Much less.

Moose is huge. Moose led to Mouse led to Moo led to Mo. M is nothing. Mo is more. Not much.

When Moo is more than you need, drop an 'o' and get some Mo.

To get just a little Mo from Mo, use "Mo Features" below.

Core Features

This is what you get. Nothing Mo.

new method

Mo provides a new object constructor. You pass it a list of name/value pairs and it returns a new object.

Constructor will not call BUILD methods. This is available using the Mo::build feature.

extends

Mo exports the extends keyword, to declare your parent class. Mo::Object itself is your default parent class.

Mo only supports single inheritance. If you need multiple inheritance or roles, you should upgrade to Moo.

has

Mo exports a has keyword, to generate accessors.

These accessors always support both get and set operations. That's it.

has name => ();
has thing => (foo => 'bar');  # arguments silently ignored

All arguments passed to has are ignored. This makes it easier to switch between Mo and Moo, without having to change all your accessors.

strict and warnings

Mo turns on use strict and use warnings for you.

Embeddable

Mo is tiny. It is compressed into a single line. You can easily inline it in your code, should you want to do that. See Mo::Inline for more information, including a utility that will do it for you.

Mo Features

Mo is the bare minimum needed for Perl OO. Many times you'll want just a couple more features. Don't worry. Mo's got you covered:

use Mo qw'build default builder coerce is required';
has name1 => ( default => sub { 'Joe' } );
has name2 => ( builder => 'name_builder' );
has name3 => ( coerce => sub {$_[0]} );
has name4 => ( is => 'ro' );
has name4 => ( required => 1 );
sub BUILD {
    my $self = shift;
    ...
}

Mo simply loads the feature classes Mo::build, Mo::default, Mo::builder, Mo::coerce, Mo::is and Mo::required. The first one supports BUILD constructing and the other three add their magics to has. A Mo::Feature module can enhance new, extends and has, and also add new export subs, or remove existing ones. Features can also be combined for a single accessor. See Mo::Features for a list of all the features and for an explanation of the Feature API..

See

Mo::Features

Mo::Inline

Mo::Hacking

Mo::Design

Status

Build Status

Authors

Ingy döt Net <[email protected]>

Damien 'dams' Krotkine <[email protected]>

Matt S. Trout (mst) <[email protected]>

Christian Walde <[email protected]>

Alessandro Ranellucci (aar/alexrj) <[email protected]>

Carlos Lima (priodev) <[email protected]>

Copyright and License

Copyright (c) 2011-2016. Ingy döt Net.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See http://www.perl.com/perl/misc/Artistic.html

mo-pm's People

Contributors

alranel avatar book avatar carloslima avatar dams avatar daoswald avatar dolmen avatar grinnz avatar ingydotnet avatar leont avatar lucasbuchala avatar melo avatar nawglan avatar nfg avatar perlpilot avatar perlpunk avatar shadowcat-mst avatar veryrusty avatar wchristian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mo-pm's Issues

ReadMe.pod in the root of /path/lib/perl5

If I install Mo into /path/lib then I get
/path/lib/perl5/ReadMe.pod and
/path/lib/perl5/Mo.pod
Both have the same content. I think ReadMe.pod should be removed.

I just found this while looking for pod files in the perl lib and was wondering what ReadMe.pod is about.

Request: don't check for (or don't enforce) /\.pm$/

Thank you for this module, which I am using for the first time. I am inlining Mo into a script that does not have a .pm extension. However, Mo::Inline insists on that extension:

mo-pm/lib/Mo/Inline.pm

Lines 33 to 34 in 442ab04

die "'$name' is not a Perl module"
if -f $name and $name !~ /\.pm$/;

Would you be willing to

  • remove that check,
  • change it from die to warn, or
  • add an option to proceed anyway (--force?)

Thank you for considering this request!

(Yes, the workaround is trivial, so this is a nice-to-have, and is not a blocking issue :) )

allow chaining

accessor chaining would be very useful:

package Hello;
use Mo;
has 'first';
has 'second';

my $hello = Hello->new;
$hello->first('foo')->second('bar');
print $hello->first;
print $hello->second;

nonlazy switch breaks inheritance?

I noticed the following strange behaviour regarding the nonlazy option for default values in class hierarchies. Consider the following three files:

A.pm:

package A;
use Mo qw(default);
has foo => 17;
1;

B.pm:

package B;
use Mo qw(default);
extends 'A';
has bar => 42;
1;

use.pl:

#!/usr/bin/env perl
use strict;
use warnings;
use feature 'say';

use FindBin;
use lib $FindBin::Bin;
use A;
use B;

my $a = A->new;
say $a->foo;

my $b = B->new;
say $b->foo, $b->bar;

The output is as expected:

$ perl use.pl 
17
1742

Setting the option nonlazy in A.pm, line 2:

use Mo qw(default nonlazy);

leads to this warning;

$ perl use.pl 
17
Use of uninitialized value in say at use.pl line 15.
42

What am I doing wrong?

WL-POOL1-PNT-06947:mo-demo memowe$ perl -MMo -E 'say $Mo::VERSION'
0.40
WL-POOL1-PNT-06947:mo-demo memowe$ perl -V
Summary of my perl5 (revision 5 version 26 subversion 0) configuration:
   
  Platform:
    osname=darwin
    osvers=15.6.0
    archname=darwin-2level
    uname='darwin wl-pool4-pnt-02505.uni-muenster.de 15.6.0 darwin kernel version 15.6.0: thu sep 1 15:01:16 pdt 2016; root:xnu-3248.60.11~2release_x86_64 x86_64 '
    config_args='-de -Dprefix=/Users/memowe/perl5/perlbrew/perls/perl-5.26.0 -Aeval:scriptdir=/Users/memowe/perl5/perlbrew/perls/perl-5.26.0/bin'
    hint=recommended
    useposix=true
    d_sigaction=define
    useithreads=undef
    usemultiplicity=undef
    use64bitint=define
    use64bitall=define
    uselongdouble=undef
    usemymalloc=n
    default_inc_excludes_dot=define
    bincompat5005=undef
  Compiler:
    cc='cc'
    ccflags ='-fno-common -DPERL_DARWIN -mmacosx-version-min=10.11 -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -DPERL_USE_SAFE_PUTENV'
    optimize='-O3'
    cppflags='-fno-common -DPERL_DARWIN -mmacosx-version-min=10.11 -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include'
    ccversion=''
    gccversion='4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)'
    gccosandvers=''
    intsize=4
    longsize=8
    ptrsize=8
    doublesize=8
    byteorder=12345678
    doublekind=3
    d_longlong=define
    longlongsize=8
    d_longdbl=define
    longdblsize=16
    longdblkind=3
    ivtype='long'
    ivsize=8
    nvtype='double'
    nvsize=8
    Off_t='off_t'
    lseeksize=8
    alignbytes=8
    prototype=define
  Linker and Libraries:
    ld='cc'
    ldflags =' -mmacosx-version-min=10.11 -fstack-protector-strong -L/usr/local/lib'
    libpth=/usr/local/lib /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/8.0.0/lib /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib /usr/lib
    libs=-lpthread -ldbm -ldl -lm -lutil -lc
    perllibs=-lpthread -ldl -lm -lutil -lc
    libc=
    so=dylib
    useshrplib=false
    libperl=libperl.a
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_dlopen.xs
    dlext=bundle
    d_dlsymun=undef
    ccdlflags=' '
    cccdlflags=' '
    lddlflags=' -mmacosx-version-min=10.11 -bundle -undefined dynamic_lookup -L/usr/local/lib -fstack-protector-strong'


Characteristics of this binary (from libperl): 
  Compile-time options:
    HAS_TIMES
    PERLIO_LAYERS
    PERL_COPY_ON_WRITE
    PERL_DONT_CREATE_GVSV
    PERL_MALLOC_WRAP
    PERL_OP_PARENT
    PERL_PRESERVE_IVUV
    PERL_USE_SAFE_PUTENV
    USE_64_BIT_ALL
    USE_64_BIT_INT
    USE_LARGE_FILES
    USE_LOCALE
    USE_LOCALE_COLLATE
    USE_LOCALE_CTYPE
    USE_LOCALE_NUMERIC
    USE_LOCALE_TIME
    USE_PERLIO
    USE_PERL_ATOF
  Locally applied patches:
    Devel::PatchPerl 1.46
  Built under darwin
  Compiled at May 31 2017 14:41:14
  %ENV:
    PERLBREW_BASHRC_VERSION="0.78"
    PERLBREW_HOME="/Users/memowe/.perlbrew"
    PERLBREW_MANPATH="/Users/memowe/perl5/perlbrew/perls/perl-5.26.0/man"
    PERLBREW_PATH="/Users/memowe/perl5/perlbrew/bin:/Users/memowe/perl5/perlbrew/perls/perl-5.26.0/bin"
    PERLBREW_PERL="perl-5.26.0"
    PERLBREW_ROOT="/Users/memowe/perl5/perlbrew"
    PERLBREW_VERSION="0.78"
  @INC:
    /Users/memowe/perl5/perlbrew/perls/perl-5.26.0/lib/site_perl/5.26.0/darwin-2level
    /Users/memowe/perl5/perlbrew/perls/perl-5.26.0/lib/site_perl/5.26.0
    /Users/memowe/perl5/perlbrew/perls/perl-5.26.0/lib/5.26.0/darwin-2level
    /Users/memowe/perl5/perlbrew/perls/perl-5.26.0/lib/5.26.0

Default defaults too often

Given the following code:

use 5.014;
package Foo {
    use Mo;

    has 'foo', is => 'rw', default => sub { say 'defaulting!'; 5 }
}

my $a = Foo->new;
say $a->foo;
$a->foo(undef);
say $a->foo;

The output is:

defaulting!
5
defaulting!
5

If we change Mo to Moose, defaulting happens only once. Not sure if bug, or just confusing.

Undefined subroutine &main::main::

Just for my own record, not to forget to add test case and fix for this issue.

Undefined subroutine &main::main:: called at lib/YAML/Mo.pm line 5, <$IN> line 1.

"required" exception message gives no clue as to caller location

In Mo/required.pm "die" is used to raise an exception when a required attributed is not provided to a constructor. This unhelpfully gives the location of the Mo installation, and not the callers location, which makes it very hard to track down which part of the code is broken.

is ro

better exception message would be helpful if trying to set a read-only accessor, currently, there is no custom exception message, should be Moose like

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.